home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / pascal / xlibpas.zip / XLIB.PAS < prev    next >
Pascal/Delphi Source File  |  1993-10-24  |  102KB  |  6,029 lines

  1. {╔══════════════════════════════════════════════════════════════════════════╗
  2.  ║                                                                          ║
  3.  ║               XLIB v1.0 for BORLAND/TURBO PASCAL 6.0/7.0                 ║
  4.  ║                                                                          ║
  5.  ╠══════════════════════════════════════════════════════════════════════════╣
  6.  ║                                                                                                                                                     ║
  7.  ║                                            Original version written by                                    ║
  8.  ║             Themie Gouthas  (egg@dstos3.dsto.gov.au / teg@bart.dsto.gov.au)     ║
  9.  ║                                                                                                                                                     ║
  10.  ║                                   Conversion to Borland/Turbo Pascal by                                      ║
  11.  ║                                 Tristan Tarrant (tristant@cogs.susx.ac.uk)                                ║
  12.  ║                                                                                                                                                     ║
  13.  ╚══════════════════════════════════════════════════════════════════════════╝}
  14.  
  15. Unit XLib;
  16.  
  17. Interface
  18.  
  19. Type
  20.     Vertex = record
  21.         x, y : word;
  22.     end;
  23.     VBMInfoStruc = record
  24.         Size, ImageWidth, ImageHeight : word;
  25.     end;
  26.     VBMAlignmentStruc = record
  27.         ImagePtr, MaskPtr : word;
  28.     end;
  29.     AlignmentHeader = record
  30.         size, ImageWidth, ImageHeight : word;
  31.         alignments : array[0..3] of
  32.         record
  33.              ImagePtr, MaskPtr : word;
  34.         end;
  35.     end;
  36.     LBMHeader = record
  37.         width, height : byte;
  38.     end;
  39.     PAlignmentHeader = ^AlignmentHeader;
  40.  
  41. Const
  42.     XMode320x200    = 0;
  43.     XMode320x240    = 1;
  44.     XMode360x200  = 2;
  45.     XMode360x240  = 3;
  46.     XMode376x282  = 4;
  47.     XMode320x400  = 5;
  48.     XMode320x480  = 6;
  49.     XMode360x400  = 7;
  50.     XMode360x480  = 8;
  51.     XMode360x360  = 9;
  52.     XMode376x308  = 10;
  53.     XMode376x564  = 11;
  54.     XMode256x200  = 12;
  55.     XMode256x240  = 13;
  56.  
  57.     RBackward            = 0;
  58.     RForward      = 1;
  59.     InvalidXMode    = -1;
  60.     Error         = 1;
  61.     AlignData          = 6;
  62.     TweakValues : array[0..180] of word =
  63.         ( $0200, $0014, $E317, 320, 200,
  64.             $0AE3, $0D06, $3E07, $4109, $EA10, $AC11, $DF12, $0014, $E715, $0616,
  65.                 $E317, 320, 240,
  66.             $08E7, $6B00, $5901, $5A02, $8E03, $5E04, $8A05, $0014, $E317, 360, 200,
  67.             $11E7, $6b00, $5901, $5A02, $8E03, $5E04, $8A05, $0D06, $3E07, $4109,
  68.                 $EA10, $AC11, $DF12, $2D13, $0014, $E715, $0616, $E317, 360, 240,
  69.             $12E7, $6E00, $5D01, $5E02, $9103, $06204, $8F05, $6206, $F007, $6109,
  70.                 $310F, $3710, $8911, $3312, $2F13, $0014, $3C15, $5C16, $E317, 376, 564,
  71.             $03E3, $4009 ,$0014, $E317, 320, 400,
  72.             $0AE3, $0D06, $3E07, $4009, $EA10, $AC11, $DF12, $0014, $E715, $0616,
  73.                 $E317, 320, 480,
  74.             $09E7, $6B00, $5901, $5A02, $8E03, $5E04, $8A05, $4009, $0014, $E317,
  75.                 360, 400,
  76.             $11E7, $6B00, $5901, $5A02, $8E03, $5E04, $8A05, $0D06, $3E07, $4009,
  77.                 $EA10, $AC11, $DF12, $2D13, $0014, $E715, $0616, $E317, 360, 480,
  78.             $0FE7, $6b00, $5901, $5A02, $8E03, $5E04, $8A05, $4009, $8810, $8511,
  79.                 $6712, $2D13, $0014, $6D15, $BA16, $E317, 360, 360,
  80.             $12E7, $6E00, $5D01, $5E02, $9103, $6204, $8F05, $6206, $0F07, $4009,
  81.                 $310F, $3710, $8911, $3312, $2F13, $0014, $3C15, $5C16, $E317, 376, 308,
  82.             $12E7, $6E00, $5D01, $5E02, $9103, $6204, $8F05, $6206, $F007, $6009,
  83.                 $310F, $3710, $8911, $3312, $2F13, $0014, $3C15, $5C16, $E317, 376, 564 );
  84.  
  85.     ModeTable : array[0..11] of word =
  86.         ( Ofs(TweakValues[0]), Ofs(TweakValues[5]), Ofs(TweakValues[18]),
  87.             Ofs(TweakValues[29]), Ofs(TweakValues[49]), Ofs(TweakValues[70]),
  88.             Ofs(TweakValues[76]), Ofs(TweakValues[89]), Ofs(TweakValues[101]),
  89.             Ofs(TweakValues[121]), Ofs(TweakValues[139]), Ofs(TweakValues[160]) );
  90.  
  91.     MirrorTable : array[0..255] of byte =
  92.         ( 0,128, 64,192, 32,160, 96,224, 16,144, 80,208, 48,176,112,240,
  93.             8,136, 72,200, 40,168,104,232, 24,152, 88,216, 56,184,120,248,
  94.             4,132, 68,196, 36,164,100,228, 20,148, 84,212, 52,180,116,244,
  95.          12,140, 76,204, 44,172,108,236, 28,156, 92,220, 60,188,124,252,
  96.             2,130, 66,194, 34,162, 98,226, 18,146, 82,210, 50,178,114,242,
  97.          10,138, 74,202, 42,170,106,234, 26,154, 90,218, 58,186,122,250,
  98.             6,134, 70,198, 38,166,102,230, 22,150, 86,214, 54,182,118,246,
  99.          14,142, 78,206, 46,174,110,238, 30,158, 94,222, 62,190,126,254,
  100.             1,129, 65,193, 33,161, 97,225, 17,145, 81,209, 49,177,113,241,
  101.             9,137, 73,201, 41,169,105,233, 25,153, 89,217, 57,185,121,249,
  102.             5,133, 69,197, 37,165,101,229, 21,149, 85,213, 53,181,117,245,
  103.          13,141, 77,205, 45,173,109,237, 29,157, 93,221, 61,189,125,253,
  104.             3,131, 67,195, 35,163, 99,227, 19,147, 83,211, 51,179,115,243,
  105.          11,139, 75,203, 43,171,107,235, 27,155, 91,219, 59,187,123,251,
  106.             7,135, 71,199, 39,167,103,231, 23,151, 87,215, 55,183,119,247,
  107.          15,143, 79,207, 47,175,111,239, 31,159, 95,223, 63,191,127,255 );
  108.  
  109.     PelPanMask : array[0..3] of byte =
  110.         ( 0, 2, 4, 6 );
  111.     LeftClipPlaneMask  : array[0..3] of byte =
  112.         ( $0F, $0E, $0C, $08 );
  113.     RightClipPlaneMask : array[0..3] of byte =
  114.         ( $0F, $01, $03, $07 );
  115.     ColumnMask : array[0..3] of byte =
  116.         ( $11, $22, $44, $88 );
  117.     LeftMaskTable : array[0..8] of byte =
  118.         ( 0, $ff, $ee, 0, $cc, 0, 0, 0, $88 );
  119.     RightMaskTable: array[0..8] of byte =
  120.         (    0, $11, $33, 0, $77, 0, 0, 0, $ff );
  121.     InitMouseDef : array[0..13] of byte =
  122.         (1,3,7,15,31,63,127,255,31,27,48,48,96,96);
  123.     LeftDelay : array[0..3] of byte =
  124.         ( 0, 1, 2, 4 );
  125.     RightDelay : array[0..3] of byte =
  126.         ( 0, 4, 2, 1 );
  127.  
  128.     MaskedPointSize = 11;
  129.     AcIndex       =  $03C0;
  130.     MiscOutput    =  $03C2;
  131.     ScIndex       =  $03C4;
  132.     GcIndex       =  $03CE;
  133.     CrtcIndex     =  $03D4;
  134.     DACReadIndex  =  $03C7;
  135.     DACWriteIndex =  $03C8;
  136.     DACData       =  $03C9;
  137.     InputStatus0  =  $03DA;
  138.     ScreenSeg     =  $0A000;
  139.     MapMask       =  $02;
  140.     ReadMap       =  $04;
  141.     BitMask       =  $08;
  142.     Overflow      =  $07;
  143.     MaxScanLine   =  $09;
  144.     AddrHigh      =  $0C;
  145.     AddrLow       =  $0D;
  146.     CrtcOffset    =  $13;
  147.     Underline     =  $14;
  148.     ModeControl   =  $17;
  149.     LineCompare   =  $18;
  150.     AcModeControl =  $10;
  151.     PelPanning    =  $13;
  152.     PatternBuffer =  $0FFFC;
  153.     OK            =  0;
  154.     LastXMode     =  11;
  155.     RolAl         =  $0C0D0;
  156.     ShortStore8   =  $044C6;
  157.     Store8        =  $084C6;
  158.     ShortStore16  =  $044C7;
  159.     Store16       =  $084C7;
  160.     AdcSiImmed    =  $0D683;
  161.     OutAl         =  $0EE;
  162.     Return        =  $0CB;
  163.     LowWord       =  0;
  164.     HighWord      =  2;
  165.     XCoord          =  4;
  166.     YCoord          =  0;
  167.     E1Src           =  48;
  168.     C1Src              =  40;
  169.     C2Src           =  32;
  170.     E2Src           =  24;
  171.     E1Dest          =  48;
  172.     P1Dest          =  40;
  173.     P4Dest          =  32;
  174.     P6Dest          =  24;
  175.     P5Dest          =  16;
  176.     P2Dest          =  8;
  177.     E2Dest          =  0;
  178.     E1Draw          =  24;
  179.     C1Draw          =  16;
  180.     C2Draw          =  8;
  181.     E2Draw          =  0;
  182.     LeftPressed   =  1;
  183.     RightPressed  =  2;
  184.     i86       = 0;
  185.     i186      = 1;
  186.     i286      = 2;
  187.     i386sx    = 3;
  188.     i386dx    = 4;
  189.     i486      = 5;
  190.     NONE      = 0;
  191.     MDA       = 1;
  192.     CGA       = 2;
  193.     EGAMono   = 3;
  194.     EGAColor  = 4;
  195.     VGAMono   = 5;
  196.     VGAColor  = 6;
  197.     MCGAMono  = 7;
  198.     MCGAColor = 8;
  199.     PS2CARDS : array[0..12] of byte = ( 0,1,2,2,4,3,2,5,6,2,8,7,8 );
  200.     TIMERVECT    = $08;
  201.     PICCMD       = $20;
  202.     NONSPECEOI   = $20;
  203.     TIMERMODE    = $34;
  204.     TIMERCONTROL = $43;
  205.     TIMER0       = $40;
  206.     LATCHCOUNT   = $00;
  207.     INTINADVANCE = 100;
  208.     DOSGETVECT   = $3500;
  209.     DOSSETVECT   = $2500;
  210.  
  211.  
  212.     
  213.  
  214. Var
  215.     InGraphics,
  216.     ErrorValue,
  217.     FontDriverActive,
  218.     CharHeight,
  219.     CharWidth,
  220.     FirstChar,
  221.     UserChHeight,
  222.     UserChWidth,
  223.     UserFirstCh,
  224.     DoubleScanFlag : Byte;
  225.     CurrXMode,
  226.     ScrnPhysicalByteWidth,
  227.     ScrnPhysicalPixelWidth,
  228.     ScrnPhysicalHeight,
  229.     SplitScrnOffs,
  230.     SplitScrnScanLine,
  231.     SplitScrnVisibleHeight,
  232.     SplitScrnActive,
  233.     Page0Offs,
  234.     Page1Offs,
  235.     Page2Offs,
  236.     ScrnLogicalByteWidth,
  237.     ScrnLogicalPixelWidth,
  238.     ScrnLogicalHeight,
  239.     MaxScrollX,
  240.     MaxScrollY,
  241.     DoubleBufferActive,
  242.     TripleBufferActive,
  243.     VisiblePageIdx,
  244.     HiddenPageOffs,
  245.     VisiblePageOffs,
  246.     WaitingPageOffs,
  247.     NonVisualOffs,
  248.     TopClip,
  249.     BottomClip,
  250.     LeftClip,
  251.     RightClip,
  252.     PhysicalStartPixelX,
  253.     PhysicalStartByteX,
  254.     PhysicalStartY,
  255.     VsyncHandlerActive,
  256.     MouseRefreshFlag,
  257.     StartAddressFlag,
  258.     WaitingStartLow,
  259.     WaitingStartHigh,
  260.     WaitingPelPan,
  261.     VsyncPaletteStart,
  262.     VsyncPaletteCount,
  263.     MirrorTableOffs,
  264.     MouseInstalled,
  265.     MouseHidden,
  266.     MouseButtonStatus,
  267.     MouseButtonCount,
  268.     MouseX,
  269.     MouseY,
  270.     OldHandlerSeg,
  271.     OldHandlerOffs,
  272.     OldHandlerMask,
  273.     OldX,
  274.     OldY,
  275.     OldScrnOffs,
  276.     BGSaveOffs,
  277.     TopBound,
  278.     BottomBound,
  279.     LeftBound,
  280.     RightBound,
  281.     MouseVersion,
  282.     TicksPerSecond,
  283.     VsyncIntTicksLo,
  284.     VsyncIntTicksHi,
  285.     VsyncPeriod,
  286.     ClockRate,
  287.     ClockCounter,
  288.     UserVsyncOffs,
  289.     UserVsyncSeg,
  290.     InUserHandler,
  291.     StackSeg,
  292.     StackPtr,
  293.     ElapsedVrts,
  294.     VrtsToSkip : word;
  295.     MouseFrozen,
  296.     MouseColor,
  297.     MouseType,
  298.     MouseIRQ,
  299.     inhandler : byte;
  300.     FontPtr,
  301.     UserFontPtr,
  302.     F8x8Ptr,
  303.     F8x14Ptr,
  304.     MouseVSyncHandler : pointer;
  305.     MouseMask : array[0..167] of byte;
  306.     VSyncPaletteBuffer : array[0..767] of byte;
  307.  
  308. Function    XSetMode( Mode, WidthInPixels : Word ) : Word; { works ! }
  309. Procedure XSelectDefaultPlane( Plane : Byte ); { works ! }
  310. Procedure XSetSplitscreen( Line : Word ); { works ! }
  311. Procedure XSetStartAddr( X, Y : Word ); { works ! }
  312. Procedure XHideSplitscreen; { works ! }
  313. Procedure XShowSplitscreen; { works ! }
  314. Procedure XAdjustSplitscreen( Line : Word ); { works ! }
  315. Procedure    XSetDoubleBuffer( PageHeight : Word ); { works ! }
  316. Procedure XSetTripleBuffer( PageHeight : word );
  317. Procedure XPageFlip( X, Y : Word ); { works ! }
  318. Procedure XSetClipRect( Left, Top, Right, Bottom : Word );
  319. Procedure XTextMode; { works ! }
  320. Procedure XWaitVsync; { works ! }
  321. Procedure XLine( x1, y1, x2, y2, Color, PgOffs : word ); { works ! }
  322. Procedure XPutPix( X,Y,PgOfs,Color:word ); { works ! }
  323. Function  XGetPix( x,y,PageBase:word ) : word; { works ! }
  324. Procedure XRectFill( StartX,StartY,EndX,EndY,PageBase,Color:word ); { works ! }
  325. Procedure XRectPattern( StartX,StartY,EndX,EndY,PageBase:word;
  326.                                                 var Pattern); { works ! }
  327. Procedure XCpVidRect( SrcStartX,SrcStartY,SrcEndX,SrcEndY,DestStartX,
  328.                                             DestStartY,SrcPageBase,DestPageBase,SrcBitmapW,
  329.                                             DestBitmapW:word );
  330. Procedure XShiftRect( SrcLeft,SrcTop,SrcRight,SrcBottom,DestLeft,DestTop,
  331.                                             ScreenOffs:word ); { works ! }
  332. Procedure XCircle( Left, Top, Diameter, Color, ScreenOffs:word ); { works ! }
  333. Procedure XFilledCircle( Left, Top, Diameter, Color, ScreenOffs:word ); { works ! }
  334. Procedure XPbmToBm( var source, dest ); { works ! }
  335. Procedure XBmToPbm( var source, dest ); { works ! }
  336. Procedure XPutMaskedPbm( X, Y,ScrnOffs : word; var Bitmap ); { works ! }
  337. Procedure XPutPbm( X,Y,ScrnOffs:word; var Bitmap ); { works ! }
  338. Procedure XGetPbm( X,Y: word;SrcWidth,SrcHeight:byte;
  339.                                      ScrnOffs:word; var Bitmap );  { works ! }
  340. Procedure XCompilePbm( LogicalWidth : word; var bitmap, output ); { works ! }
  341. Function  XSizeOfCPbm( logicalwidth : word; var bitmap ) : word; { works ! }
  342. Procedure XCompileBitmap( logicalwidth:word; var bitmap, output ); { works ! }
  343. Function  XSizeOfCBitmap( logicalwidth:word; var bitmap ):word; { works ! }
  344. Procedure XPutCBitmap( XPos,YPos,PageOffset:word; var Sprite ); { works ! }
  345. Procedure XGetPalStruc( var PalBuff; NumColors,StartColor:word ); { works ! }
  346. Procedure XGetPalRaw( Var PalBuff; NumColors,StartColor:word ); { works ! }
  347. Procedure XPutPalStruc( Var CompPalBuff ); { works ! }
  348. Procedure XTransposePalStruc( Var CompPalBuff; StartColor:word );
  349. Procedure XPutPalRaw( Var PalBuff; NumColors,StartColor:word ); { works ! }
  350. Procedure XSetRGB( ColorIndex,R,G,B:byte ); { works ! }
  351. Procedure XRotPalStruc( Var PalBuff; Direction:word ); { works ! }
  352. Procedure XRotPalRaw( Var PalBuff; Direction, NumColors:word ); { works ! }
  353. Function  XCpContrastPalStruc( Var PalSrcBuff,PalDestBuff; Intensity:byte ) : word; { works ! }
  354. Procedure XPutContrastPalStruc( Var CompPalBuff; Intensity:byte );
  355. Function  XCharPut( Chr:char; X, Y, ScrnOffs, Color:word ) : byte; { works ! }
  356. Procedure XSetFont( FontID : word ); { works ! }
  357. Procedure XTextInit; { works ! }
  358. Procedure XRegisterUserFont( var FontToRegister ); { works ! }
  359. Procedure XPrintf( x, y, ScrnOffs, Color : word; s : string ); { works ! }
  360. Procedure XBgPrintf( x, y, ScrnOffs, fgcolor, bgcolor : word; s : string ); { works ! }
  361. Procedure XTriangle( X0, Y0, X1, Y1, X2, Y2, Color, PageOffset:word ); { works ! }
  362. Procedure XPolygon( var vertices; numvertices, Color, PageOffset:word ); { works ! }
  363. Procedure XPutCursor( X, Y, TopClip, BottomClip, ScrnOffs : word );
  364. Procedure XDefineMouseCursor( var MouseDef; MouseColor:byte );
  365. procedure XMouseInit; { works ! }
  366. Procedure XMouseWindow( x0, y0, x1, y1:word ); { works ! }
  367. procedure XShowMouse; { works ! }
  368. Procedure XHideMouse; { works ! }
  369. Procedure XMouseRemove; { works ! }
  370. Procedure XPositionMouse( X, Y : word ); { works ! }
  371. Procedure XUpdateMouse; { works ! }
  372. Procedure XPutMaskedPBMClipX( X, Y, ScrnOffs:word; var Bitmap ); { works ! }
  373. procedure XPutMaskedPBMClipY( X, Y, ScrnOffs:word; var Bitmap ); { works ! }
  374. Procedure XPutMaskedPBMClipXY( X, Y, ScrnOffs:word; var Bitmap ); { works ! }
  375. Procedure XPutPBMClipX( X, Y, ScrnOffs:word; var Bitmap ); { works ! }
  376. Procedure XPutPBMClipY( X, Y, ScrnOffs : word; var Bitmap ); { works ! }
  377. Procedure XPutPBMClipXY( X, Y, ScrnOffs:word; var Bitmap ); { works ! }
  378. Procedure XStoreVBMImage( VramOffs,Align:word; var LBitmap ); { works ! }
  379. Procedure XPutMaskedVBM( X, Y, ScrnOffs:word; var SrcVBM ); { works ! }
  380. Procedure XPutMaskedVBMClipX( X, Y, ScrnOffs:word; var SrcVBM ); { works ! }
  381. Procedure XPutMaskedVBMClipY( X, Y, ScrnOffs : word; var SrcVBM ); { works ! }
  382. Procedure XPutMaskedVBMClipXY( X, Y, ScrnOffs:word; var SrcVBM ); { works ! }
  383. Function  XMakeVBM( var lbm; var VramStart : word ) : PAlignmentHeader; { works ! }
  384.  
  385. Implementation
  386.  
  387. Function    XSetMode( Mode, WidthInPixels : Word ) : Word; assembler;
  388. asm
  389.     mov InGraphics,0
  390.     mov ErrorValue,0
  391.     mov DoubleScanFlag,0
  392.     mov CurrXMode,0
  393.     mov ScrnPhysicalByteWidth,0
  394.     mov    ScrnPhysicalPixelWidth,0
  395.     mov ScrnPhysicalHeight,0
  396.     mov SplitScrnOffs,0
  397.     mov SplitScrnScanLine,0
  398.     mov SplitScrnVisibleHeight,0
  399.     mov SplitScrnActive,0
  400.     mov Page0Offs,0
  401.     mov Page1Offs,0
  402.     mov Page2Offs,0
  403.     mov ScrnLogicalByteWidth,0
  404.     mov ScrnLogicalPixelWidth,0
  405.     mov ScrnLogicalHeight,0
  406.     mov MaxScrollX,0
  407.     mov MaxScrollY,0
  408.     mov DoubleBufferActive,0
  409.     mov VisiblePageIdx,0
  410.     mov HiddenPageOffs,0
  411.     mov VisiblePageOffs,0
  412.     mov NonVisualOffs,0
  413.     mov TopClip,0
  414.     mov BottomClip,0
  415.     mov LeftClip,0
  416.     mov RightClip,0
  417.     mov PhysicalStartPixelX,0
  418.     mov PhysicalStartByteX,0
  419.     mov PhysicalStartY,0
  420.     cld
  421.     mov   ax,ds
  422.     mov   es,ax
  423.     mov   cx,mode
  424.     cmp   cx,13
  425.     jle   @@ValidMode
  426.     mov   InGraphics,0
  427.     mov   ax,-1
  428.     jmp @@Done
  429.  
  430. @@ValidMode:
  431.     mov   CurrXMode,cx
  432.     mov   InGraphics,1
  433.     xor   al,al
  434.     cmp   cx,3
  435.     jg    @@SetDoubleScanFlag
  436.     mov   al,1
  437.  
  438. @@SetDoubleScanFlag:
  439.     mov   DoubleScanFlag,al
  440.     push  cx
  441.     mov   ax,13h
  442.     int   10h
  443.     pop   cx
  444.     mov   dx,ScIndex
  445.     mov   ax,0604h
  446.     out   dx,ax
  447.     mov   ax,0100h
  448.     out   dx,ax
  449.     mov   bx,offset ModeTable
  450.     shl   cx,1
  451.     add   bx,cx
  452.     mov   si, word ptr [bx]
  453.     lodsb
  454.     or    al,al
  455.     jz    @@DontSetDot
  456.     mov   dx,MISCOUTPUT
  457.     out   dx,al
  458.  
  459. @@DontSetDot:
  460.     mov   dx,ScIndex
  461.     mov   ax,0300h
  462.     out   dx,ax
  463.     mov   dx,CrtcIndex
  464.     mov   al,11h
  465.     out   dx,al
  466.     inc   dx
  467.     in    al,dx
  468.     and   al,07fh
  469.     out   dx,al
  470.     dec   dx
  471.     cld
  472.     xor   cx,cx
  473.     lodsb
  474.     mov   cl,al
  475.  
  476. @@SetCRTParmsLoop:
  477.     lodsw
  478.  
  479.     out   dx,ax
  480.     loop  @@SetCRTParmsLoop
  481.     mov   dx,ScIndex
  482.     mov   ax,0f02h
  483.     out   dx,ax
  484.     mov   ax,ScreenSeg
  485.     mov   es,ax
  486.     sub   di,di
  487.     sub   ax,ax
  488.     mov   cx,8000h
  489.     rep   stosw
  490.     lodsw
  491.     mov   ScrnPhysicalPixelWidth,ax
  492.     mov   SplitScrnScanLine,ax
  493.     mov   bx,ax
  494.     shr   ax,2
  495.     mov   ScrnPhysicalByteWidth,ax
  496.     lodsw
  497.     mov   ScrnPhysicalHeight,ax
  498.     mov   cx,widthinpixels
  499.     mov   dx,CrtcIndex
  500.     mov   al,CRTCOFFSET
  501.     out   dx,al
  502.     inc   dx
  503.     mov   ax,cx
  504.     cmp   ax,ScrnPhysicalPixelWidth
  505.     jge   @@ValidLogicalWidth
  506.     mov   ax,bx
  507.  
  508. @@ValidLogicalWidth:
  509.     shr   ax,3
  510.     out   dx,al
  511.     shl   ax,1
  512.     mov   bx,ax
  513.     mov   ScrnLogicalByteWidth,ax
  514.     mov   RightClip,ax
  515.     sub   ax,ScrnPhysicalByteWidth
  516.     shl   ax,2
  517.     mov   MaxScrollX,ax
  518.     mov   ax,bx
  519.     shl   ax,2
  520.     mov   ScrnLogicalPixelWidth,ax
  521.     mov   cx,ax
  522.     mov   ax,0ffffh
  523.     sub   dx,dx
  524.     div   bx
  525.     mov   ScrnLogicalHeight,ax
  526.     mov   BottomClip,ax
  527.     sub   ax,ScrnPhysicalHeight
  528.     mov   MaxScrollY,ax
  529.     mov   ax,cx
  530.     mov   ax,ScrnLogicalByteWidth
  531.     mul   ScrnPhysicalHeight
  532.     mov   NonVisualOffs,ax
  533.  
  534. @@Done:
  535.     mov        ax, 0CB00h
  536.     int        10h
  537.  
  538. End;
  539.  
  540. Procedure XSelectDefaultPlane( Plane : Byte ); assembler;
  541. asm
  542.     mov  cl,Plane
  543.     and  cl,011b
  544.     mov  ax,0100h + MapMask
  545.     shl  ah,cl
  546.     mov  dx,ScIndex
  547.     out  dx,ax
  548.     mov  ah,cl
  549.     mov  al,ReadMap
  550.     mov  dx,GcIndex
  551.     out  dx,ax
  552. end;
  553.  
  554. Procedure XSetSplitscreen( Line : Word ); assembler;
  555. asm
  556.     xor  si,si
  557.     cmp  DoubleBufferActive,0
  558.     jne  @@error
  559.     cmp  SplitScrnActive,0
  560.     je   @@NotPreviouslyCalled
  561.  
  562. @@error:
  563.     mov  ErrorValue,ERROR
  564.     ret
  565.  
  566. @@NotPreviouslyCalled:
  567.     mov  dx,InputStatus0
  568.     in   al,dx
  569.     mov  al,ACMODECONTROL+20h
  570.     mov  dx,ACINDEX
  571.     out  dx,al
  572.     inc  dx
  573.     in   al,dx
  574.     or   al,20h
  575.     dec  dx
  576.     out  dx,al
  577.     mov  PhysicalStartByteX,ax
  578.     mov  PhysicalStartPixelX,ax
  579.     mov  PhysicalStartY,ax
  580.     mov  SplitScrnActive,1
  581.     mov  ax,Line
  582.     jns  @@NotNeg
  583.     mov  ax,0
  584.  
  585. @@NotNeg:
  586.     mov  SplitScrnScanLine,ax
  587.     or   DoubleScanFlag,0
  588.     jz   @@NotDoubleScanned
  589.     shl  ax,1
  590.     dec  ax
  591.  
  592. @@NotDoubleScanned:
  593.     mov  bx,ax
  594.     mov  dx,InputStatus0
  595.  
  596. @@WaitNotVsync:
  597.     in   al,dx
  598.     test al,08h
  599.     jnz  @@WaitNotVsync
  600.  
  601. @@WaitVsync:
  602.     in   al,dx
  603.     test al,08h
  604.     jz   @@WaitVsync
  605.     cli
  606.     mov  dx,CrtcIndex
  607.     mov  ah,bl
  608.     mov  al,LINECOMPARE
  609.     out  dx,ax
  610.     mov  ah,bh
  611.     and  ah,1
  612.     shl  ah,4
  613.     mov  al,Overflow
  614.     out  dx,al
  615.     inc  dx
  616.     in   al,dx
  617.     and  al, not 10h
  618.     or   al,ah
  619.     out  dx,al
  620.     dec  dx
  621.     mov  ah,bh
  622.     and  ah,2
  623.     ror  ah,3
  624.     mov  al,MAXSCANLINE
  625.     out  dx,al
  626.     inc  dx
  627.     in   al,dx
  628.     and  al, not 40h
  629.     or   al,ah
  630.     out  dx,al
  631.     sti
  632.     mov  ax,ScrnPhysicalHeight
  633.     sub  ax,SplitScrnScanLine
  634.     mov  SplitScrnVisibleHeight,bx
  635.     mov  bx,ScrnLogicalByteWidth
  636.     mul  bx
  637.     mov  Page0Offs,ax
  638.     mov  Page1Offs,ax
  639.     mov  Page2Offs,ax
  640.     mov  cx,0ffffh
  641.     sub  cx,ax
  642.     xchg cx,ax
  643.     sub  dx,dx
  644.     div  bx
  645.     mov  ScrnLogicalHeight,ax
  646.     cmp  ax,BottomClip
  647.     jle  @@BottomClipOK
  648.     mov  BottomClip,ax
  649.  
  650. @@BottomClipOK:
  651.     sub  ax,SplitScrnScanLine
  652.     mov  MaxScrollY,ax
  653.     xchg cx,ax
  654.     mov  bh,al
  655.     mov  ch,ah
  656.     mov  bl,ADDRLOW
  657.     mov  cl,ADDRHIGH
  658.     and  si,0003h
  659.     mov  ah,byte ptr PelPanMask[si]
  660.     mov  al,PELPANNING+20h
  661.     mov  si,ax
  662.     mov  dx,InputStatus0
  663.  
  664. @@WaitDE:
  665.     in   al,dx
  666.     test al,01h
  667.     jnz  @@WaitDE
  668.     mov  dx,CrtcIndex
  669.     mov  ax,bx
  670.     out  dx,ax
  671.     mov  ax,cx
  672.     out  dx,ax
  673.     mov  dx,ACINDEX
  674.     mov  ax,si
  675.     out  dx,al
  676.     mov  al,ah
  677.     out  dx,al
  678.     mov  dx,InputStatus0
  679.  
  680. @@WaitVS:
  681.     in   al,dx
  682.     test al,08h
  683.     jz @@WaitVS
  684.     mov  ErrorValue,OK
  685. end;
  686.  
  687. Procedure XSetStartAddr( X, Y : Word ); assembler;
  688. asm
  689.     mov  si,x
  690.     mov  ax,ScrnLogicalByteWidth
  691.     mov  cx,y
  692.     mul  cx
  693.     cmp  DoubleBufferActive,1
  694.     je   @@PageResolution
  695.     cmp  TripleBufferActive,1
  696.     je   @@PageResolution
  697.  
  698. @@PageFlipEntry1:
  699.     add  ax,Page0Offs
  700.     jmp  @@AddColumn
  701.  
  702. @@PageFlipEntry2:
  703.     mov  PhysicalStartPixelX,si
  704.     mov  PhysicalStartY,cx
  705.  
  706. @@PageResolution:
  707.     add  ax,VisiblePageOffs
  708.  
  709. @@AddColumn:
  710.     mov  cx,si
  711.     shr  cx,2
  712.     mov  PhysicalStartByteX,cx
  713.     add  ax,cx
  714.     mov  bh,al
  715.     mov  ch,ah
  716.  
  717. @@StartAddrEntry:
  718.     mov  bl,ADDRLOW
  719.     mov  cl,ADDRHIGH
  720.     and  si,0003h
  721.     mov  ah,byte ptr PelPanMask[si]
  722.     mov  al,PELPANNING+20h
  723.     mov  si,ax
  724.  
  725.     mov  dx,InputStatus0
  726. @@WaitDE:
  727.     in   al,dx
  728.     test al,01h
  729.     jnz  @@WaitDE
  730.  
  731.     mov  dx,CrtcIndex
  732.     mov  ax,bx
  733.     cli
  734.     out  dx,ax
  735.     mov  ax,cx
  736.     out  dx,ax
  737.     sti
  738.     mov  dx,InputStatus0
  739.  
  740. @@WaitVS:
  741.     in   al,dx
  742.     test al,08h
  743.     jz @@WaitVS
  744.     mov  dx,ACINDEX
  745.     mov  ax,si
  746.     cli
  747.     out  dx,al
  748.     mov  al,ah
  749.     out  dx,al
  750.     sti
  751.     mov  ErrorValue,OK
  752. end;
  753.  
  754. Procedure XHideSplitscreen; assembler;
  755. asm
  756.     cmp  SplitScrnActive,1
  757.     je   @@SplitScreenEnabled
  758.  
  759. @@error:
  760.     mov  ErrorValue,ERROR
  761.     jmp  @@Done
  762.  
  763. @@SplitScreenEnabled:
  764.     cmp  CurrXMode,4
  765.     jg   @@error
  766.     mov  bx,ScrnPhysicalHeight
  767.     mov  ax,ScrnLogicalHeight
  768.     sub  ax,bx
  769.     mov  MaxScrollY,ax
  770.     xor  ax,ax
  771.     mov  SplitScrnVisibleHeight,ax
  772.     or   DoubleScanFlag,0
  773.     jz   @@NotDoubleScanned
  774.     shl  bx,1
  775.     dec  bx
  776.  
  777. @@NotDoubleScanned:
  778.  
  779.     mov  dx,InputStatus0
  780.  
  781. @@WaitNotVsync:
  782.     in   al,dx
  783.     test al,08h
  784.     jnz  @@WaitNotVsync
  785.  
  786. @@WaitVsync:
  787.     in   al,dx
  788.     test al,08h
  789.     jz   @@WaitVsync
  790.     cli
  791.     mov  dx,CrtcIndex
  792.     mov  ah,bl
  793.     mov  al,LINECOMPARE
  794.     out  dx,ax
  795.     mov  ah,bh
  796.     and  ah,1
  797.     shl  ah,4
  798.     mov  al,Overflow
  799.     out  dx,al
  800.     inc  dx
  801.     in   al,dx
  802.     and  al, not 10h
  803.     or   al,ah
  804.     out  dx,al
  805.     dec  dx
  806.     mov  ah,bh
  807.     and  ah,2
  808.     ror  ah,3
  809.     mov  al,MAXSCANLINE
  810.     out  dx,al
  811.     inc  dx
  812.     in   al,dx
  813.     and  al, not 40h
  814.     or   al,ah
  815.     out  dx,al
  816.     sti
  817.  
  818. @@done:
  819.     mov  ErrorValue,OK
  820. end;
  821.  
  822. Procedure XShowSplitscreen; assembler;
  823. asm
  824.     cmp  SplitScrnActive,1
  825.     je   @@SplitScreenEnabled
  826.  
  827. @@error:
  828.     mov  ErrorValue,ERROR
  829.     jmp  @@Done
  830.  
  831. @@SplitScreenEnabled:
  832.     cmp  CurrXMode,4
  833.     jg   @@error
  834.     mov  bx,SplitScrnScanLine
  835.     mov  ax,ScrnLogicalHeight
  836.     sub  ax,bx
  837.     mov  MaxScrollY,ax
  838.     mov  ax,ScrnPhysicalHeight
  839.     sub  ax,bx
  840.     mov  SplitScrnVisibleHeight,ax
  841.     or   DoubleScanFlag,0
  842.     jz   @@NotDoubleScanned
  843.     shl  bx,1
  844.     dec  bx
  845.  
  846. @@NotDoubleScanned:
  847.     mov  dx,InputStatus0
  848.  
  849. @@WaitNotVsync:
  850.     in   al,dx
  851.     test al,08h
  852.     jnz  @@WaitNotVsync
  853.  
  854. @@WaitVsync:
  855.     in   al,dx
  856.     test al,08h
  857.     jz   @@WaitVsync
  858.     cli
  859.     mov  dx,CrtcIndex
  860.     mov  ah,bl
  861.     mov  al,LINECOMPARE
  862.     out  dx,ax
  863.     mov  ah,bh
  864.     and  ah,1
  865.     shl  ah,4
  866.     mov  al,Overflow
  867.     out  dx,al
  868.     inc  dx
  869.     in   al,dx
  870.     and  al, not 10h
  871.     or   al,ah
  872.     out  dx,al
  873.     dec  dx
  874.     mov  ah,bh
  875.     and  ah,2
  876.     ror  ah,3
  877.     mov  al,MAXSCANLINE
  878.     out  dx,al
  879.     inc  dx
  880.     in   al,dx
  881.     and  al, not 40h
  882.     or   al,ah
  883.     out  dx,al
  884.     sti
  885.  
  886. @@Done:
  887.     mov  ErrorValue,0
  888. end;
  889.  
  890. Procedure XAdjustSplitScreen( Line : Word ); assembler;
  891. asm
  892.     cmp  SplitScrnActive,1
  893.     je   @@SplitScreenEnabled
  894.  
  895. @@error:
  896.     mov  ErrorValue,ERROR
  897.     jmp  @@Done
  898.  
  899. @@SplitScreenEnabled:
  900.     cmp  CurrXMode,4
  901.     jg   @@error
  902.     mov  bx,Line
  903.     cmp  bx,SplitScrnScanLine
  904.     js   @@Done
  905.  
  906. @@ValidScanLine:
  907.     mov  ax,ScrnLogicalHeight
  908.     sub  ax,bx
  909.     mov  MaxScrollY,ax
  910.     mov  ax,ScrnPhysicalHeight
  911.     sub  ax,bx
  912.     mov  SplitScrnVisibleHeight,ax
  913.     or   DoubleScanFlag,0
  914.     jz   @@NotDoubleScanned
  915.     shl  bx,1
  916.     dec  bx
  917.  
  918. @@NotDoubleScanned:
  919.     mov  dx,InputStatus0
  920.  
  921. @@WaitNotVsync:
  922.     in   al,dx
  923.     test al,08h
  924.     jnz  @@WaitNotVsync
  925.  
  926. @@WaitVsync:
  927.     in   al,dx
  928.     test al,08h
  929.     jz   @@WaitVsync
  930.     cli
  931.     mov  dx,CrtcIndex
  932.     mov  ah,bl
  933.     mov  al,LINECOMPARE
  934.     out  dx,ax
  935.     mov  ah,bh
  936.     and  ah,1
  937.     shl  ah,4
  938.     mov  al,Overflow
  939.     out  dx,al
  940.     inc  dx
  941.     in   al,dx
  942.     and  al, not 10h
  943.     or   al,ah
  944.     out  dx,al
  945.     dec  dx
  946.     mov  ah,bh
  947.     and  ah,2
  948.     ror  ah,3
  949.     mov  al,MAXSCANLINE
  950.     out  dx,al
  951.     inc  dx
  952.     in   al,dx
  953.     and  al, not 40h
  954.     or   al,ah
  955.     out  dx,al
  956.     sti
  957.  
  958. @@Done:
  959.     mov  ErrorValue,OK
  960. end;
  961. Procedure XSetDoubleBuffer( PageHeight : Word ); assembler;
  962. asm
  963.     cmp   DoubleBufferActive,0
  964.     je    @@OkToContinue
  965. @error:
  966.     mov   ErrorValue,ERROR
  967.     ret
  968.  
  969. @@OkToContinue:
  970.     mov  VisiblePageIdx,0
  971.     mov  ax,ScrnLogicalHeight
  972.     shr  ax,1
  973.     mov  bx,PageHeight
  974.     cmp  ax,bx
  975.     js   @@InvalidHeight
  976.     mov  ax,bx
  977.  
  978. @@InvalidHeight:
  979.     mov   ScrnLogicalHeight,ax
  980.     cmp   ax,BottomClip
  981.     jle   @@BottomClipOK
  982.     mov   BottomClip,ax
  983. @@BottomClipOK:
  984.     mov   dx,ax
  985.     mul   ScrnLogicalByteWidth
  986.     mov   cx,ax
  987.     mov   bx,Page0Offs
  988.     mov   VisiblePageOffs,bx
  989.     add   ax,bx
  990.     mov   Page1Offs,ax
  991.     mov   HiddenPageOffs,ax
  992.     add   ax,cx
  993.     mov   NonVisualOffs,ax
  994.     mov   DoubleBufferActive,1
  995.     mov   ax,dx
  996.     sub   ax,ScrnPhysicalHeight
  997.     add   ax,SplitScrnVisibleHeight
  998.     mov   MaxScrollY,ax
  999.     mov   ax,dx
  1000.     mov   ErrorValue,OK
  1001. end;
  1002.  
  1003. Procedure XSetTripleBuffer( PageHeight : word ); assembler;
  1004. asm
  1005.     cmp   DoubleBufferActive,0
  1006.     jne   @@Error
  1007.     cmp   TripleBufferActive,0
  1008.     je    @@OkToContinue
  1009.  
  1010. @@Error:
  1011.     mov   ErrorValue,ERROR
  1012.     jmp @@Done
  1013.  
  1014. @@OkToContinue:
  1015.     mov   VisiblePageIdx,0
  1016.     mov   ax,ScrnLogicalHeight
  1017.     mov   bx,3
  1018.     xor   dx,dx
  1019.     idiv  bx
  1020.     mov   bx,PageHeight
  1021.     cmp   ax,bx
  1022.     js    @@InvalidHeight
  1023.     mov   ax,bx
  1024.  
  1025.  
  1026. @@InvalidHeight:
  1027.     mov   ScrnLogicalHeight,ax
  1028.  
  1029.     cmp   ax,BottomClip
  1030.     jle   @@BottomClipOK
  1031.     mov   BottomClip,ax
  1032. @@BottomClipOK:
  1033.     push  ax
  1034.     mul   ScrnLogicalByteWidth
  1035.     mov   cx,ax
  1036.     mov   bx,Page0Offs
  1037.     mov   VisiblePageOffs,bx
  1038.     add   ax,bx
  1039.     mov   Page1Offs,ax
  1040.     mov   HiddenPageOffs,ax
  1041.     add   ax,cx
  1042.     mov   Page2Offs,ax
  1043.     mov   WaitingPageOffs,ax
  1044.     add   ax,cx
  1045.     mov   NonVisualOffs,ax
  1046.     mov   TripleBufferActive,1
  1047.     pop   ax
  1048.     sub   ax,ScrnPhysicalHeight
  1049.     add   ax,SplitScrnVisibleHeight
  1050.     mov   MaxScrollY,ax
  1051.     mov   ax,dx
  1052.     mov   ErrorValue,OK
  1053.  
  1054. @@Done:
  1055.  
  1056. end;
  1057.  
  1058. Procedure XPageFlip( X, Y : Word ); assembler;
  1059. asm
  1060.     mov  si,x
  1061.     mov  ax,ScrnLogicalByteWidth
  1062.     mov  cx,y
  1063.     mul  cx
  1064.     cmp  DoubleBufferActive,1
  1065.     je   @@DoubleBuffer
  1066.     cmp  TripleBufferActive,1
  1067.     jne  @@PageFlipEntry1
  1068.     mov  bx,HiddenPageOffs
  1069.     xchg bx,VisiblePageOffs
  1070.     xchg bx,WaitingPageOffs
  1071.     mov  HiddenPageOffs,bx
  1072.     mov  bx, VisiblePageIdx
  1073.     inc  bx
  1074.     cmp  bx,3
  1075.     jne  @@IdxOk
  1076.     xor  bx,bx
  1077. @@IdxOk:
  1078.     mov  VisiblePageIdx,bx
  1079.     jmp  @@PageFlipEntry2
  1080.  
  1081. @@DoubleBuffer:
  1082.     mov  bx,HiddenPageOffs
  1083.     xchg bx,VisiblePageOffs
  1084.     xchg HiddenPageOffs,bx
  1085.     xor  VisiblePageIdx,01h
  1086.     jmp  @@PageFlipEntry2
  1087.  
  1088. @@PageFlipEntry1:
  1089.     add  ax,Page0Offs
  1090.     jmp  @@AddColumn
  1091.  
  1092. @@PageFlipEntry2:
  1093.     mov  PhysicalStartPixelX,si
  1094.     mov  PhysicalStartY,cx
  1095.  
  1096. @@PageResolution:
  1097.     add  ax,VisiblePageOffs
  1098.  
  1099. @@AddColumn:
  1100.     mov  cx,si
  1101.     shr  cx,2
  1102.     mov  PhysicalStartByteX,cx
  1103.     add  ax,cx
  1104.     mov  bh,al
  1105.     mov  ch,ah
  1106.  
  1107. @@StartAddrEntry:
  1108.     mov  bl,ADDRLOW
  1109.     mov  cl,ADDRHIGH
  1110.     and  si,0003h
  1111.     mov  ah,byte ptr PelPanMask[si]
  1112.     mov  al,PELPANNING+20h
  1113.     mov  si,ax
  1114.     mov  dx,InputStatus0
  1115.  
  1116. @@WaitDE:
  1117.     in   al,dx
  1118.     test al,01h
  1119.     jnz  @@WaitDE
  1120.     mov  dx,CrtcIndex
  1121.     mov  ax,bx
  1122.     out  dx,ax
  1123.     mov  ax,cx
  1124.     out  dx,ax
  1125.     mov  dx,ACINDEX
  1126.     mov  ax,si
  1127.     out  dx,al
  1128.     mov  al,ah
  1129.     out  dx,al
  1130.     mov  dx,InputStatus0
  1131.  
  1132. @@WaitVS:
  1133.     in   al,dx
  1134.     test al,08h
  1135.     jz @@WaitVS
  1136.     mov  ErrorValue,OK
  1137. end;
  1138.  
  1139. Procedure XSetClipRect( Left, Top, Right, Bottom : Word ); assembler;
  1140. asm
  1141.     mov   ax,left
  1142.     mov   bx,right
  1143.     cmp   bx,ax
  1144.     jns   @@CorrectXOrder
  1145.     xchg  bx,ax
  1146. @@CorrectXOrder:
  1147.     mov   LeftClip,ax
  1148.     mov   RightClip,bx
  1149.     mov   ax,top
  1150.     mov   bx,bottom
  1151.     cmp   bx,ax
  1152.     jns   @@CorrectYOrder
  1153.     xchg  bx,ax
  1154. @@CorrectYOrder:
  1155.     mov   TopClip,ax
  1156.     mov   BottomClip,bx
  1157. end;
  1158.  
  1159. Procedure XTextMode; assembler;
  1160. asm
  1161.     mov   ax,03h
  1162.     int   10h
  1163. end;
  1164.  
  1165. Procedure XWaitVsync; assembler;
  1166. asm
  1167.     mov   dx,InputStatus0
  1168. @@WaitNotVsync:
  1169.     in    al,dx
  1170.     test  al,08h
  1171.     jnz   @@WaitNotVsync
  1172.  
  1173. @@WaitVsync:
  1174.     in    al,dx
  1175.     test  al,08h
  1176.     jz    @@WaitVsync
  1177. end;
  1178.  
  1179. Procedure XLine( x1, y1, x2, y2, Color, PgOffs : word ); assembler;
  1180. Var
  1181.     vertincr, incr1, incr2, routine:word;
  1182. asm
  1183.     mov ax,0a000h
  1184.     mov es,ax
  1185.  
  1186.     mov dx,ScIndex
  1187.     mov si,ScrnLogicalByteWidth
  1188.     mov cx,x2
  1189.     sub cx,x1
  1190.     jz  @@VertLine
  1191.     jns @@L01
  1192.  
  1193.     neg cx
  1194.  
  1195.     mov bx,x2
  1196.     xchg  bx,x1
  1197.     mov x2,bx
  1198.  
  1199.     mov bx,y2
  1200.     xchg  bx,y1
  1201.     mov y2,bx
  1202.  
  1203. @@L01:
  1204.     mov bx,y2
  1205.     sub bx,y1
  1206.     jnz @@skip
  1207.     jmp @@HorizLine
  1208.  
  1209. @@skip:
  1210.     jns @@L03
  1211.     neg bx
  1212.     neg si
  1213.  
  1214. @@L03:
  1215.     mov vertincr,si
  1216.     mov routine,offset @@LoSlopeLine
  1217.     cmp bx,cx
  1218.     jle @@L04
  1219.     mov routine,offset @@HiSlopeLine
  1220.     xchg  bx,cx
  1221.  
  1222.  
  1223. @@L04:
  1224.     shl bx,1
  1225.     mov incr1,bx
  1226.     sub bx,cx
  1227.     mov si,bx
  1228.     sub bx,cx
  1229.     mov incr2,bx
  1230.  
  1231.     push  cx
  1232.     mov ax,y1
  1233.     mov bx,x1
  1234.     mov cl,bl
  1235.     push dx
  1236.     mov dx,ScrnLogicalByteWidth
  1237.     mul dx
  1238.     pop dx
  1239.     shr bx,2
  1240.     add bx,ax
  1241.     add bx,PgOffs
  1242.     and cl,3
  1243.     mov di,bx
  1244.     mov al,1
  1245.     shl al,cl
  1246.     mov ah,al
  1247.     shl al,4
  1248.     add ah,al
  1249.     mov bl,ah
  1250.     pop cx
  1251.     inc cx
  1252.     jmp routine
  1253.  
  1254. @@VertLine:
  1255.     mov ax,y1
  1256.     mov bx,y2
  1257.     mov cx,bx
  1258.     sub cx,ax
  1259.     jge @@L31
  1260.     neg cx
  1261.     mov ax,bx
  1262.  
  1263. @@L31:
  1264.     inc cx
  1265.     mov bx,x1
  1266.     push  cx
  1267.     mov cl,bl
  1268.     push dx
  1269.     mov dx,ScrnLogicalByteWidth
  1270.     mul dx
  1271.     pop dx
  1272.     shr bx,2
  1273.     add bx,ax
  1274.     add bx,PgOffs
  1275.     and cl,3
  1276.  
  1277.     mov ah,1
  1278.     shl ah,cl
  1279.     mov al,MapMask
  1280.     out dx,ax
  1281.     pop cx
  1282.     mov ax, word ptr [Color]
  1283.  
  1284. @@L32:
  1285.     mov es:[bx],al
  1286.     add bx,si
  1287.     loop  @@L32
  1288.     jmp @@Lexit
  1289.  
  1290. @@HorizLine:
  1291.     push  ds
  1292.  
  1293.     mov ax,y1
  1294.     mov bx,x1
  1295.     mov cl,bl
  1296.     push dx
  1297.     mov dx,ScrnLogicalByteWidth
  1298.     mul dx
  1299.     pop dx
  1300.     shr bx,2
  1301.     add bx,ax
  1302.     add bx,PgOffs
  1303.     and cl,3
  1304.  
  1305.     mov di,bx
  1306.     mov dl,00fh
  1307.     shl dl,cl
  1308.  
  1309.     mov cx,x2
  1310.     and cl,3
  1311.     mov dh,00eh
  1312.     shl dh,cl
  1313.     not dh
  1314.  
  1315.     mov ax,x2
  1316.     mov bx,x1
  1317.  
  1318.     shr ax,2
  1319.     shr bx,2
  1320.     mov cx,ax
  1321.     sub cx,bx
  1322.  
  1323.     mov ax,dx
  1324.     mov dx,SCINDEX
  1325.     mov bx, [Color]
  1326.     or  cx,cx
  1327.     jnz @@L42
  1328.     and ah,al
  1329.     jmp @@L44
  1330.  
  1331. @@L42:
  1332.     push ax
  1333.     mov ah,al
  1334.     mov al,MAPMASK
  1335.     out dx,ax
  1336.     mov al,bl
  1337.     stosb
  1338.     dec cx
  1339.  
  1340. @@L43:
  1341.     mov ah,0Fh
  1342.     mov al,MAPMASK
  1343.     out dx,ax
  1344.     mov al,bl
  1345.     rep stosb
  1346.     pop     ax
  1347.  
  1348. @@L44:
  1349.     mov al,MAPMASK
  1350.     out dx, ax
  1351.     mov     byte ptr es:[di],bl
  1352.     pop ds
  1353.     jmp @@Lexit
  1354.  
  1355.  
  1356. @@LoSlopeLine:
  1357.     mov al,MAPMASK
  1358.     mov bh,byte ptr [Color]
  1359. @@L10:
  1360.     mov ah,bl
  1361.  
  1362. @@L11:
  1363.     or  ah,bl
  1364.     rol bl,1
  1365.     jc  @@L14
  1366.  
  1367.     or  si,si
  1368.     jns @@L12
  1369.     add si,incr1
  1370.     loop  @@L11
  1371.  
  1372.     out dx,ax
  1373.     mov es:[di],bh
  1374.     jmp @@Lexit
  1375.  
  1376. @@L12:
  1377.     add si,incr2
  1378.     out dx,ax
  1379.     mov es:[di],bh
  1380.     add di,vertincr
  1381.     loop  @@L10
  1382.     jmp @@Lexit
  1383.  
  1384. @@L14:
  1385.     out dx,ax
  1386.     mov es:[di],bh
  1387.     inc di
  1388.     or  si,si
  1389.     jns @@L15
  1390.     add si,incr1
  1391.     loop  @@L10
  1392.     jmp @@Lexit
  1393.  
  1394. @@L15:
  1395.     add si,incr2
  1396.     add di,vertincr
  1397.     loop  @@L10
  1398.     jmp @@Lexit
  1399.  
  1400. @@HiSlopeLine:
  1401.     mov bx,vertincr
  1402.     mov al,MAPMASK
  1403. @@L21:
  1404.     out dx,ax
  1405.     push  ax
  1406.     mov ax,Color
  1407.     mov es:[di],al
  1408.     pop ax
  1409.     add di,bx
  1410.  
  1411. @@L22:
  1412.     or  si,si
  1413.     jns @@L23
  1414.  
  1415.     add si,incr1
  1416.     loop  @@L21
  1417.     jmp @@Lexit
  1418.  
  1419. @@L23:
  1420.     add si,incr2
  1421.     rol ah,1
  1422.     adc di,0
  1423. @@lx21: loop  @@L21
  1424.  
  1425.  
  1426. @@Lexit:
  1427. end;
  1428.  
  1429. Procedure XPutPix( X,Y,PgOfs,Color:word ); assembler;
  1430. asm
  1431.     mov  ax,ScrnLogicalByteWidth
  1432.     mul  Y
  1433.     mov  bx,X
  1434.     shr  bx,2
  1435.     add  bx,ax
  1436.     add  bx,PgOfs
  1437.     mov  ax,SCREENSEG
  1438.     mov  es,ax
  1439.  
  1440.     mov  cl,byte ptr X
  1441.     and  cl,011b
  1442.     mov  ax,0100h + MAPMASK
  1443.     shl  ah,cl
  1444.     mov  dx,SCINDEX
  1445.     out  dx,ax
  1446.     mov  al,byte ptr Color
  1447.     mov  es:[bx],al
  1448. end;
  1449.  
  1450. Function XGetPix( x,y,PageBase:word ) : word; assembler;
  1451. asm
  1452.     mov  ax,ScrnLogicalByteWidth
  1453.     mul  Y
  1454.     mov  bx,X
  1455.     shr  bx,1
  1456.     shr  bx,1
  1457.     add  bx,ax
  1458.     add  bx,PageBase
  1459.     mov  ax,SCREENSEG
  1460.     mov  es,ax
  1461.  
  1462.     mov  ah,byte ptr X
  1463.     and  ah,011b
  1464.     mov  al,READMAP
  1465.     mov  dx,GCINDEX
  1466.     out  dx,ax
  1467.     mov  al,es:[bx]
  1468.     sub  ah,ah
  1469. end;
  1470.  
  1471. Procedure XRectFill( StartX,StartY,EndX,EndY,
  1472.                         PageBase,Color:word ); assembler;
  1473. asm
  1474.     push bp
  1475.     cld
  1476.     mov  ax,ScrnLogicalByteWidth
  1477.     mul  StartY
  1478.     mov  di,StartX
  1479.     shr  di,1
  1480.     shr  di,1
  1481.     add  di,ax
  1482.     add  di,PageBase
  1483.     mov  ax,SCREENSEG
  1484.     mov  es,ax
  1485.     mov  dx,SCINDEX
  1486.     mov  al,MAPMASK
  1487.     out  dx,al
  1488.     inc  dx
  1489.     mov  si,StartX
  1490.     and  si,0003h
  1491.     mov  bh,byte ptr LeftClipPlaneMask[si]
  1492.     mov  si,EndX
  1493.     and  si,0003h
  1494.     mov  bl,byte ptr RightClipPlaneMask[si]
  1495.     mov  cx,EndX
  1496.     mov  si,StartX
  1497.     cmp  cx,si
  1498.     jle  @@FillDone
  1499.     dec  cx
  1500.     and  si,not 011b
  1501.     sub  cx,si
  1502.     shr  cx,1
  1503.     shr  cx,1
  1504.     jnz  @@MasksSet
  1505.     and  bh,bl
  1506.  
  1507. @@MasksSet:
  1508.     mov  si,EndY
  1509.     sub  si,StartY
  1510.     jle  @@FillDone
  1511.     mov  ah,byte ptr Color
  1512.     mov  bp,ScrnLogicalByteWidth
  1513.     sub  bp,cx
  1514.     dec  bp
  1515. @@FillRowsLoop:
  1516.     push cx
  1517.     mov  al,bh
  1518.     out  dx,al
  1519.     mov  al,ah
  1520.     stosb
  1521.     dec  cx
  1522.     js   @@FillLoopBottom
  1523.     jz   @@DoRightEdge
  1524.     mov  al,00fh
  1525.     out  dx,al
  1526.     mov  al,ah
  1527.     rep  stosb
  1528. @@DoRightEdge:
  1529.     mov  al,bl
  1530.     out  dx,al
  1531.     mov  al,ah
  1532.     stosb
  1533. @@FillLoopBottom:
  1534.     add  di,bp
  1535.     pop  cx
  1536.     dec  si
  1537.     jnz  @@FillRowsLoop
  1538. @@FillDone:
  1539.     pop bp
  1540. end;
  1541.  
  1542.  
  1543.  
  1544. Procedure XRectPattern( StartX,StartY,EndX,EndY,PageBase:word;
  1545.                                                 var Pattern); assembler;
  1546. Var
  1547.     NextScanOffset,RectAddrWidth,Height:word;
  1548. asm
  1549.     push ds
  1550.     cld
  1551.     mov  ax,SCREENSEG
  1552.     mov  es,ax
  1553.     lds  si,Pattern
  1554.     mov  di,PATTERNBUFFER
  1555.     mov  dx,SCINDEX
  1556.     mov  al,MAPMASK
  1557.     out  dx,al
  1558.     inc  dx
  1559.     mov  cx,4
  1560. @@DownloadPatternLoop:
  1561.     mov  al,1
  1562.     out  dx,al
  1563.     movsb
  1564.     dec  di
  1565.     mov  al,2
  1566.     out  dx,al
  1567.     movsb
  1568.     dec  di
  1569.     mov  al,4
  1570.     out  dx,al
  1571.     movsb
  1572.     dec  di
  1573.     mov  al,8
  1574.     out  dx,al
  1575.     movsb
  1576.     loop @@DownloadPatternLoop
  1577.     pop  ds
  1578.  
  1579.     mov  dx,GCINDEX
  1580.     mov  ax,00000h+BITMASK
  1581.     out  dx,ax
  1582.  
  1583.     mov  ax,StartY
  1584.     mov  si,ax
  1585.     and  si,011b
  1586.     add  si,PATTERNBUFFER
  1587.  
  1588.     mov  dx,ScrnLogicalByteWidth
  1589.     mul  dx
  1590.     mov  di,StartX
  1591.     mov  bx,di
  1592.     shr  di,1
  1593.     shr  di,1
  1594.     add  di,ax
  1595.     add  di,PageBase
  1596.  
  1597.     and  bx,0003h
  1598.     mov  ah,byte ptr LeftClipPlaneMask[bx]
  1599.     mov  bx,EndX
  1600.     and  bx,0003h
  1601.     mov  al,byte ptr RightClipPlaneMask[bx]
  1602.     mov  bx,ax
  1603.  
  1604.     mov  cx,EndX
  1605.     mov  ax,StartX
  1606.     cmp  cx,ax
  1607.     jle  @@FillDone
  1608.     dec  cx
  1609.     and  ax,not 011b
  1610.     sub  cx,ax
  1611.     shr  cx,1
  1612.     shr  cx,1
  1613.     jnz  @@MasksSet
  1614.     and  bh,bl
  1615.  
  1616. @@MasksSet:
  1617.     mov  ax,EndY
  1618.     sub  ax,StartY
  1619.     jle  @@FillDone
  1620.     mov  Height,ax
  1621.     mov  ax,ScrnLogicalByteWidth
  1622.     sub  ax,cx
  1623.     dec  ax
  1624.     mov  NextScanOffset,ax
  1625.     mov  RectAddrWidth,cx
  1626.     mov  dx,SCINDEX+1
  1627.  
  1628. @@FillRowsLoop:
  1629.     mov  cx,RectAddrWidth
  1630.     mov  al,es:[si]
  1631.     inc  si
  1632.     jnz  @@NoWrap
  1633.     sub  si,4
  1634. @@NoWrap:
  1635.     mov  al,bh
  1636.     out  dx,al
  1637.                 stosb
  1638.  
  1639.     dec  cx
  1640.     js   @@FillLoopBottom
  1641.     jz   @@DoRightEdge
  1642.     mov  al,00fh
  1643.     out  dx,al
  1644.     rep  stosb
  1645.  
  1646. @@DoRightEdge:
  1647.     mov  al,bl
  1648.     out  dx,al
  1649.     stosb
  1650.  
  1651. @@FillLoopBottom:
  1652.     add  di,NextScanOffset
  1653.     dec  word ptr Height
  1654.     jnz  @@FillRowsLoop
  1655. @@FillDone:
  1656.     mov  dx,GCINDEX+1
  1657.     mov  al,0ffh
  1658.     out  dx,al
  1659. end;
  1660.  
  1661. Procedure XCpVidRect( SrcStartX,SrcStartY,SrcEndX,SrcEndY,DestStartX,
  1662.                                             DestStartY,SrcPageBase,DestPageBase,SrcBitmapW,
  1663.                                             DestBitmapW:word ); assembler;
  1664. var
  1665.     SrcNextOffs,DestNextOffs,RectAddrW,Height:word;
  1666. asm
  1667.     push    ds
  1668.     cld
  1669.     mov     dx,GCINDEX
  1670.     mov     ax,BITMASK
  1671.     out dx,ax
  1672.     mov     ax,SCREENSEG
  1673.                 mov     es,ax
  1674.     mov     ax,DestBitmapW
  1675.     shr     ax,2
  1676.     mul     DestStartY
  1677.     mov     di,DestStartX
  1678.     shr     di,2
  1679.     add     di,ax
  1680.     add     di,DestPageBase
  1681.     mov     ax,SrcBitmapW
  1682.     shr     ax,2
  1683.     mul     SrcStartY
  1684.     mov     si,SrcStartX
  1685.     mov     bx,si
  1686.     shr     si,2
  1687.     add     si,ax
  1688.     add     si,SrcPageBase
  1689.     and     bx,0003h
  1690.     mov     ah,byte ptr LeftClipPlaneMask[bx]
  1691.     mov     bx,SrcEndX
  1692.     and     bx,0003h
  1693.     mov     al,byte ptr RightClipPlaneMask[bx]
  1694.     mov     bx,ax
  1695.     mov     cx,SrcEndX
  1696.     mov     ax,SrcStartX
  1697.     cmp     cx,ax
  1698.     jle     @@CopyDone
  1699.     dec     cx
  1700.     and     ax,not 011b
  1701.     sub     cx,ax
  1702.     shr     cx,2
  1703.     jnz     @@MasksSet
  1704.     and     bh,bl
  1705. @@MasksSet:
  1706.     mov     ax,SrcEndY
  1707.     sub     ax,SrcStartY
  1708.     jle     @@CopyDone
  1709.     mov     Height,ax
  1710.     mov     ax,DestBitmapW
  1711.     shr     ax,2
  1712.     sub     ax,cx
  1713.     dec     ax
  1714.     mov     DestNextOffs,ax
  1715.     mov     ax,SrcBitmapW
  1716.     shr     ax,2
  1717.     sub     ax,cx
  1718.     dec     ax
  1719.     mov     SrcNextOffs,ax
  1720.     mov     RectAddrW,cx
  1721.     mov     dx,SCINDEX+1
  1722.     mov     ax,es
  1723.     mov     ds,ax
  1724. @@CopyRowsLoop:
  1725.     mov     cx,RectAddrW
  1726.     mov     al,bh
  1727.     out     dx,al
  1728.     movsb
  1729.     dec     cx
  1730.     js      @@CopyLoopBottom
  1731.     jz      @@DoRightEdge
  1732.     mov     al,00fh
  1733.     out     dx,al
  1734.     rep     movsb
  1735. @@DoRightEdge:
  1736.     mov     al,bl
  1737.     out     dx,al
  1738.     movsb
  1739. @@CopyLoopBottom:
  1740.     add     si,SrcNextOffs
  1741.     add     di,DestNextOffs
  1742.     dec     word ptr Height
  1743.     jnz     @@CopyRowsLoop
  1744. @@CopyDone:
  1745.     mov     dx,GCINDEX+1
  1746.     mov     al,0ffh
  1747.     out     dx,al
  1748.     pop     ds
  1749. End;
  1750.  
  1751. Procedure XShiftRect( SrcLeft,SrcTop,SrcRight,SrcBottom,DestLeft,DestTop,
  1752.                                             ScreenOffs:word ); assembler;
  1753. Var
  1754.     widthtemp:word;
  1755. asm
  1756.     push ds
  1757.     mov si, SrcLeft
  1758.     shr si, 2
  1759.  
  1760.     mov di, DestLeft
  1761.     shr di, 2
  1762.  
  1763.     mov bx, SrcRight
  1764.     add bx, 3
  1765.     shr bx, 2
  1766.     sub bx, si
  1767.     mov ax, bx
  1768.     inc bx
  1769.     mov widthtemp, bx
  1770.  
  1771.     cld
  1772.  
  1773.     cmp si, di
  1774.     jge @@MovingLeft
  1775.  
  1776.     add si, ax
  1777.     add di, ax
  1778.     neg bx
  1779.     std
  1780.  
  1781. @@MovingLeft:
  1782.  
  1783.     mov cx, ScrnLogicalByteWidth
  1784.     mov ax, SrcTop
  1785.     mov dx, DestTop
  1786.     cmp ax, dx
  1787.     jge @@MovingUp
  1788.  
  1789.     mov ax, SrcBottom
  1790.     add dx, ax
  1791.     sub dx, SrcTop
  1792.     neg cx
  1793.  
  1794. @@MovingUp:
  1795.     push dx
  1796.     mul ScrnLogicalByteWidth
  1797.     add si, ax
  1798.     pop ax
  1799.     mul ScrnLogicalByteWidth
  1800.     add di, ax
  1801.  
  1802.     sub cx, bx
  1803.  
  1804.     add si, ScreenOffs
  1805.     add di, ScreenOffs
  1806.  
  1807.     mov dx, SCINDEX
  1808.     mov ax, 00f02h
  1809.     out dx, ax
  1810.  
  1811.     mov dx, GCINDEX
  1812.     mov ax, BITMASK
  1813.     out dx, ax
  1814.  
  1815.     mov ax, SCREENSEG
  1816.     mov es, ax
  1817.     mov ds, ax
  1818.  
  1819.     mov ah, byte ptr widthtemp
  1820.  
  1821.     mov bx, SrcBottom
  1822.     sub bx, SrcTop
  1823.  
  1824.     mov dx, cx
  1825.  
  1826.     xor ch, ch
  1827.  
  1828. @@LineLoop:
  1829.     mov cl, ah
  1830.     rep movsb
  1831.  
  1832.     add si, dx
  1833.     add di, dx
  1834.  
  1835.     dec bx
  1836.     jge @@LineLoop
  1837.  
  1838.     mov dx, GCINDEX + 1
  1839.     mov al, 0ffh
  1840.     out dx, al
  1841.     pop ds
  1842. End;
  1843.  
  1844.  
  1845.  
  1846.  
  1847. Procedure XCircle( Left, Top, Diameter, Color, ScreenOffs:word ); assembler;
  1848. Var
  1849.     offset0,offset1,offset2,offset3,offset4,offset5,offset6,offset7,mask0n1,
  1850.     mask2n3,mask4n5,mask6n7,shrunkradius,diametereven,error:word;
  1851. asm
  1852.     push ds
  1853.     mov di, ScrnLogicalByteWidth
  1854.     xor dx, dx
  1855.     mov ax, Diameter
  1856.     dec ax
  1857.     shr ax, 1
  1858.     adc dx, 0
  1859.     mov shrunkradius, ax
  1860.     mov diametereven, dx
  1861.     add ax, Top
  1862.     mul di
  1863.     add ax, ScreenOffs
  1864.  
  1865.     mov bx, Left
  1866.     mov cx, bx
  1867.     mov si, bx
  1868.     shr si, 2
  1869.     add si, ax
  1870.     mov offset6, si
  1871.     and bx, 3
  1872.     mov bl, byte ptr ColumnMask[bx]
  1873.     mov mask6n7, bx
  1874.  
  1875.     add cx, Diameter
  1876.     dec cx
  1877.     mov bx, cx
  1878.     shr cx, 2
  1879.     add cx, ax
  1880.     mov offset2, cx
  1881.     and bx, 3
  1882.     mov bl, byte ptr ColumnMask[bx]
  1883.     mov mask2n3, bx
  1884.  
  1885.     cmp diametereven, 1
  1886.     jne @@MiddlePlotsOverlap
  1887.     add si, di
  1888.     add cx, di
  1889. @@MiddlePlotsOverlap:
  1890.     mov offset7, si
  1891.     mov offset3, cx
  1892.  
  1893.     mov bx, Left
  1894.     add bx, shrunkradius
  1895.  
  1896.     mov ax, Top
  1897.     mul di
  1898.     add ax, ScreenOffs
  1899.     mov si, ax
  1900.  
  1901.     mov ax, Diameter
  1902.     dec ax
  1903.     mul di
  1904.     add ax, si
  1905.  
  1906.     mov di, bx
  1907.     shr di, 2
  1908.     add si, di
  1909.     mov offset4, si
  1910.     add di, ax
  1911.     mov offset5, di
  1912.     and bx, 3
  1913.     mov bl, byte ptr ColumnMask[bx]
  1914.     mov mask4n5, bx
  1915.  
  1916.     cmp diametereven, 1
  1917.     jne @@TopAndBottomPlotsOverlap
  1918.     rol bl, 1
  1919.     jnc @@TopAndBottomPlotsOverlap
  1920.     inc si
  1921.     inc di
  1922. @@TopAndBottomPlotsOverlap:
  1923.     mov offset0, si
  1924.     mov offset1, di
  1925.     mov mask0n1, bx
  1926.     mov bx, ScrnLogicalByteWidth
  1927.  
  1928.     mov dx, SCREENSEG
  1929.     mov ds, dx
  1930.  
  1931.     mov dx, SCINDEX
  1932.     mov al, MAPMASK
  1933.     out dx, al
  1934.     inc dx
  1935.  
  1936.     mov si, Diameter
  1937.     inc si
  1938.  
  1939.     mov cx, si
  1940.     neg cx
  1941.     add cx, 2
  1942.     mov error, cx
  1943.  
  1944.     xor cx, cx
  1945.     mov ah, byte ptr Color
  1946.     jmp @@CircleCalc
  1947.  
  1948. @@NoAdvance:
  1949.     mov al, byte ptr mask0n1
  1950.     out dx, al
  1951.     mov di, offset0
  1952.     mov [di], ah
  1953.     rol al, 1
  1954.     mov byte ptr mask0n1, al
  1955.     adc di, 0
  1956.     mov offset0, di
  1957.     mov di, offset1
  1958.     mov [di], ah
  1959.     ror al, 1
  1960.     adc di, 0
  1961.     mov offset1, di
  1962.  
  1963.     mov al, byte ptr mask2n3
  1964.     out dx, al
  1965.     mov di, offset2
  1966.     mov [di], ah
  1967.     sub di, bx
  1968.     mov offset2, di
  1969.     mov di, offset3
  1970.     mov [di], ah
  1971.     add di, bx
  1972.     mov offset3, di
  1973.  
  1974.     mov al, byte ptr mask4n5
  1975.     out dx, al
  1976.     mov di, offset4
  1977.     mov [di], ah
  1978.     ror al, 1
  1979.     mov byte ptr mask4n5, al
  1980.     sbb di, 0
  1981.     mov offset4, di
  1982.     mov di, offset5
  1983.     mov [di], ah
  1984.     rol al, 1
  1985.     sbb di, 0
  1986.     mov offset5, di
  1987.  
  1988.     mov al, byte ptr mask6n7
  1989.     out dx, al
  1990.     mov di, offset6
  1991.     mov [di], ah
  1992.     sub di, bx
  1993.     mov offset6, di
  1994.     mov di, offset7
  1995.     mov [di], ah
  1996.     add di, bx
  1997.     mov offset7, di
  1998.  
  1999.     jmp @@CircleCalc
  2000.  
  2001. @@Advance:
  2002.     mov al, byte ptr mask0n1
  2003.     out dx, al
  2004.     mov di, offset0
  2005.     mov [di], ah
  2006.     rol al, 1
  2007.     mov byte ptr mask0n1, al
  2008.     adc di, bx
  2009.     mov offset0, di
  2010.     mov di, offset1
  2011.     mov [di], ah
  2012.     ror al, 1
  2013.     adc di, 0
  2014.     sub di, bx
  2015.     mov offset1, di
  2016.  
  2017.     mov al, byte ptr mask2n3
  2018.     out dx, al
  2019.     mov di, offset2
  2020.     mov [di], ah
  2021.     ror al, 1
  2022.     mov byte ptr mask2n3, al
  2023.     sbb di, bx
  2024.     mov offset2, di
  2025.     mov di, offset3
  2026.     mov [di], ah
  2027.     rol al, 1
  2028.     sbb di, 0
  2029.     add di, bx
  2030.     mov offset3, di
  2031.  
  2032.     mov al, byte ptr mask4n5
  2033.     out dx, al
  2034.     mov di, offset4
  2035.     mov [di], ah
  2036.     ror al, 1
  2037.     mov byte ptr mask4n5, al
  2038.     sbb di, 0
  2039.     add di, bx
  2040.     mov offset4, di
  2041.     mov di, offset5
  2042.     mov [di], ah
  2043.     rol al, 1
  2044.     sbb di, bx
  2045.     mov offset5, di
  2046.  
  2047.     mov al, byte ptr mask6n7
  2048.     out dx, al
  2049.     mov di, offset6
  2050.     mov [di], ah
  2051.     rol al, 1
  2052.     mov byte ptr mask6n7, al
  2053.     adc di, 0
  2054.     sub di, bx
  2055.     mov offset6, di
  2056.     mov di, offset7
  2057.     mov [di], ah
  2058.     ror al, 1
  2059.     adc di, bx
  2060.     mov offset7, di
  2061.  
  2062. @@CircleCalc:
  2063.     add cx, 2
  2064.     mov di, error
  2065.     add di, cx
  2066.     inc di
  2067.     jl @@CircleNoError
  2068.     cmp cx, si
  2069.     ja @@FleeFlyFlowFum
  2070.     sub si, 2
  2071.     sub di, si
  2072.     mov error, di
  2073.     jmp @@Advance
  2074. @@CircleNoError:
  2075.     mov error, di
  2076.     jmp @@NoAdvance
  2077.  
  2078. @@FleeFlyFlowFum:
  2079.     pop ds
  2080. end;
  2081.  
  2082.  
  2083.  
  2084.  
  2085. Procedure XFilledCircle( Left, Top, Diameter, Color, ScreenOffs:word ); assembler;
  2086. Var
  2087.     offset0,offset1,offset2,offset3,offset4,offset5,offset6,offset7,mask0n1,
  2088.     mask2n3,mask4n5,mask6n7,shrunkradius,diametereven,error,jumpvector:word;
  2089. asm
  2090.     cld
  2091.     mov di, ScrnLogicalByteWidth
  2092.     xor dx, dx
  2093.     mov ax, Diameter
  2094.     dec ax
  2095.     shr ax, 1
  2096.     adc dx, 0
  2097.     mov shrunkradius, ax
  2098.     mov diametereven, dx
  2099.     add ax, Top
  2100.     mul di
  2101.     add ax, ScreenOffs
  2102.  
  2103.     mov bx, Left
  2104.     mov cx, bx
  2105.     mov si, bx
  2106.     shr si, 2
  2107.     add si, ax
  2108.     mov offset6, si
  2109.     and bx, 3
  2110.     mov bl, byte ptr ColumnMask[bx]
  2111.     mov mask6n7, bx
  2112.  
  2113.     add cx, Diameter
  2114.     dec cx
  2115.     mov bx, cx
  2116.     shr cx, 2
  2117.     add cx, ax
  2118.     mov offset2, cx
  2119.     and bx, 3
  2120.     mov bl, byte ptr ColumnMask[bx]
  2121.     mov mask2n3, bx
  2122.  
  2123.     cmp diametereven, 1
  2124.     jne @@MiddlePlotsOverlap
  2125.     add si, di
  2126.     add cx, di
  2127. @@MiddlePlotsOverlap:
  2128.     mov offset7, si
  2129.     mov offset3, cx
  2130.  
  2131.     mov bx, Left
  2132.     add bx, shrunkradius
  2133.  
  2134.     mov ax, Top
  2135.     mul di
  2136.     add ax, ScreenOffs
  2137.     mov si, ax
  2138.  
  2139.     mov ax, Diameter
  2140.     dec ax
  2141.     mul di
  2142.     add ax, si
  2143.  
  2144.     mov di, bx
  2145.     shr di, 2
  2146.     add si, di
  2147.     mov offset4, si
  2148.     add di, ax
  2149.     mov offset5, di
  2150.     and bx, 3
  2151.     mov bl, byte ptr ColumnMask[bx]
  2152.     mov mask4n5, bx
  2153.  
  2154.     cmp diametereven, 1
  2155.     jne @@TopAndBottomPlotsOverlap
  2156.     rol bl, 1
  2157.     jnc @@TopAndBottomPlotsOverlap
  2158.     inc si
  2159.     inc di
  2160. @@TopAndBottomPlotsOverlap:
  2161.     mov offset0, si
  2162.     mov offset1, di
  2163.     mov mask0n1, bx
  2164.  
  2165.     mov bx, ScrnLogicalByteWidth
  2166.  
  2167.     mov dx, SCREENSEG
  2168.     mov es, dx
  2169.  
  2170.     mov dx, SCINDEX
  2171.     mov al, MAPMASK
  2172.     out dx, al
  2173.     inc dx
  2174.     mov si, Diameter
  2175.     inc si
  2176.  
  2177.     mov cx, si
  2178.     neg cx
  2179.     add cx, 2
  2180.     mov error, cx
  2181.     xor cx, cx
  2182.     mov ah, byte ptr Color
  2183.     jmp @@FilledCircleCalc
  2184. @@PlotLines:
  2185.     push cx
  2186.  
  2187.     mov di, mask0n1
  2188.     and di, 0000fh
  2189.     mov al, byte ptr RightMaskTable[di]
  2190.     mov di, offset0
  2191.     cmp di, offset4
  2192.     jne @@PlotXMajorNontrivial
  2193.     mov di, mask4n5
  2194.     and di, 0000fh
  2195.     and al, byte ptr LeftMaskTable[di]
  2196.     out dx, al
  2197.     mov di, offset4
  2198.     mov es:[di], ah
  2199.     mov di, offset5
  2200.     mov es:[di], ah
  2201.     jmp @@PlotYMajor
  2202. @@PlotXMajorNontrivial:
  2203.     out dx, al
  2204.     mov es:[di], ah
  2205.     mov di, offset1
  2206.     mov es:[di], ah
  2207.  
  2208.     mov di, mask4n5
  2209.     and di, 0000fh
  2210.     mov al, byte ptr LeftMaskTable[di]
  2211.     out dx, al
  2212.     mov di, offset4
  2213.     mov es:[di], ah
  2214.     mov di, offset5
  2215.     mov es:[di], ah
  2216.  
  2217.     mov al, 0ffh
  2218.     out dx, al
  2219.     mov al, ah
  2220.     inc di
  2221.     mov cx, offset1
  2222.     sub cx, di
  2223.     push cx
  2224.     shr cx, 1
  2225.     rep stosw
  2226.     adc cx, 0
  2227.     rep stosb
  2228.  
  2229.     mov di, offset4
  2230.     inc di
  2231.     pop cx
  2232.     shr cx, 1
  2233.     rep stosw
  2234.     adc cx, 0
  2235.     rep stosb
  2236.  
  2237. @@PlotYMajor:
  2238.     mov di, mask2n3
  2239.     and di, 0000fh
  2240.     mov al, byte ptr RightMaskTable[di]
  2241.     mov di, offset2
  2242.     cmp di, offset6
  2243.     jne @@PlotYMajorNontrivial
  2244.     mov di, mask6n7
  2245.     and di, 0000fh
  2246.     and al, byte ptr LeftMaskTable[di]
  2247.     out dx, al
  2248.     mov di, offset6
  2249.     mov es:[di], ah
  2250.     mov di, offset7
  2251.     mov es:[di], ah
  2252.     jmp @@ClimaxOfPlot
  2253. @@PlotYMajorNontrivial:
  2254.     out dx, al
  2255.     mov es:[di], ah
  2256.     mov di, offset3
  2257.     mov es:[di], ah
  2258.  
  2259.     mov di, mask6n7
  2260.     and di, 0000fh
  2261.     mov al, byte ptr LeftMaskTable[di]
  2262.     out dx, al
  2263.     mov di, offset6
  2264.     mov es:[di], ah
  2265.     mov di, offset7
  2266.     mov es:[di], ah
  2267.  
  2268.     mov al, 0ffh
  2269.     out dx, al
  2270.     mov al, ah
  2271.  
  2272.     inc di
  2273.     mov cx, offset3
  2274.     sub cx, di
  2275.     push cx
  2276.     shr cx, 1
  2277.     rep stosw
  2278.     adc cx, 0
  2279.     rep stosb
  2280.  
  2281.     mov di, offset6
  2282.     inc di
  2283.     pop cx
  2284.     shr cx, 1
  2285.     rep stosw
  2286.     adc cx, 0
  2287.     rep stosb
  2288.  
  2289. @@ClimaxOfPlot:
  2290.     pop cx
  2291.     jmp [jumpvector]
  2292.  
  2293.  
  2294. @@NoAdvance:
  2295.     mov al, byte ptr mask0n1
  2296.     mov di, offset0
  2297.     rol al, 1
  2298.     mov byte ptr mask0n1, al
  2299.     adc di, 0
  2300.     mov offset0, di
  2301.     mov di, offset1
  2302.     ror al, 1
  2303.     adc di, 0
  2304.     mov offset1, di
  2305.  
  2306.     mov al, byte ptr mask4n5
  2307.     mov di, offset4
  2308.     ror al, 1
  2309.     mov byte ptr mask4n5, al
  2310.     sbb di, 0
  2311.     mov offset4, di
  2312.     mov di, offset5
  2313.     rol al, 1
  2314.     sbb di, 0
  2315.     mov offset5, di
  2316.  
  2317.     mov al, byte ptr mask2n3
  2318.     mov di, offset2
  2319.     sub di, bx
  2320.     mov offset2, di
  2321.     mov di, offset3
  2322.     add di, bx
  2323.     mov offset3, di
  2324.  
  2325.     mov al, byte ptr mask6n7
  2326.     mov di, offset6
  2327.     sub di, bx
  2328.     mov offset6, di
  2329.     mov di, offset7
  2330.     add di, bx
  2331.     mov offset7, di
  2332.  
  2333.     jmp @@FilledCircleCalc
  2334.  
  2335. @@Advance:
  2336.     mov al, byte ptr mask0n1
  2337.     mov di, offset0
  2338.     rol al, 1
  2339.     mov byte ptr mask0n1, al
  2340.     adc di, bx
  2341.     mov offset0, di
  2342.     mov di, offset1
  2343.     ror al, 1
  2344.     adc di, 0
  2345.     sub di, bx
  2346.     mov offset1, di
  2347.  
  2348.     mov al, byte ptr mask2n3
  2349.     mov di, offset2
  2350.     ror al, 1
  2351.     mov byte ptr mask2n3, al
  2352.     sbb di, bx
  2353.     mov offset2, di
  2354.     mov di, offset3
  2355.     rol al, 1
  2356.     sbb di, 0
  2357.     add di, bx
  2358.     mov offset3, di
  2359.  
  2360.     mov al, byte ptr mask4n5
  2361.     mov di, offset4
  2362.     ror al, 1
  2363.     mov byte ptr mask4n5, al
  2364.     sbb di, 0
  2365.     add di, bx
  2366.     mov offset4, di
  2367.     mov di, offset5
  2368.     rol al, 1
  2369.     sbb di, bx
  2370.     mov offset5, di
  2371.  
  2372.     mov al, byte ptr mask6n7
  2373.     mov di, offset6
  2374.     rol al, 1
  2375.     mov byte ptr mask6n7, al
  2376.     adc di, 0
  2377.     sub di, bx
  2378.     mov offset6, di
  2379.     mov di, offset7
  2380.     ror al, 1
  2381.     adc di, bx
  2382.     mov offset7, di
  2383.  
  2384. @@FilledCircleCalc:
  2385.     add cx, 2
  2386.     mov di, error
  2387.     add di, cx
  2388.     inc di
  2389.     jl @@FilledCircleNoError
  2390.     cmp cx, si
  2391.     ja @@FleeFlyFlowFum
  2392.     sub si, 2
  2393.     sub di, si
  2394.     mov error, di
  2395.     mov jumpvector, offset @@Advance
  2396.     jmp @@PlotLines
  2397. @@FilledCircleNoError:
  2398.     mov error, di
  2399.     mov jumpvector, offset @@NoAdvance
  2400.     jmp @@PlotLines
  2401.  
  2402. @@FleeFlyFlowFum:
  2403. end;
  2404.  
  2405. Procedure XPbmToBm( var source, dest ); assembler;
  2406. asm
  2407.     push ds
  2408.     les  di,dest
  2409.     lds  si,source
  2410.     lodsb
  2411.     mov  bl,al
  2412.     xor  ah,ah
  2413.     shl  ax,2
  2414.     cmp  ax,255
  2415.     ja   @@WidthError
  2416.     stosb
  2417.     lodsb
  2418.     stosb
  2419.     xor  ah,ah
  2420.     mul  bl
  2421.     mov  dx,di
  2422.     mov  bl,3
  2423.  
  2424. @@PlaneLoop:
  2425.     mov  cx,ax
  2426.  
  2427. @@PixelLoop:
  2428.     movsb
  2429.     add  di,3
  2430.     loop @@PixelLoop
  2431.  
  2432.     inc  dx
  2433.     mov  di,dx
  2434.     dec  bl
  2435.     jns  @@PlaneLoop
  2436.     xor  ax,ax
  2437.     jmp  @@Done
  2438. @@WidthError:
  2439.     mov  ax,1
  2440.  
  2441. @@Done:
  2442.     pop  ds
  2443. end;
  2444.  
  2445. Procedure XBmToPbm( var source, dest ); assembler;
  2446. asm
  2447.     push ds
  2448.     les  di,dest
  2449.     lds  si,source
  2450.     lodsb
  2451.     test al,03h
  2452.     jnz  @@WidthIncompatible
  2453.     shr  al,2
  2454.     stosb
  2455.     mov  bl,al
  2456.     lodsb
  2457.     stosb
  2458.     xor  ah,ah
  2459.     mul  bl
  2460.     mov  dx,si
  2461.     mov  bl,3
  2462.  
  2463. @@PlaneLoop:
  2464.     mov  cx,ax
  2465.  
  2466. @@PixelLoop:
  2467.     movsb
  2468.     add  si,3
  2469.     loop @@PixelLoop
  2470.  
  2471.     inc  dx
  2472.     mov  si,dx
  2473.     dec  bl
  2474.     jns  @@PlaneLoop
  2475.     xor  ax,ax
  2476.     jmp  @@Done
  2477. @@WidthIncompatible:
  2478.     mov  ax,1
  2479.  
  2480. @@Done:
  2481.     pop  ds
  2482. end;
  2483.  
  2484. Procedure XPutMaskedPbm( X, Y,ScrnOffs : word; var Bitmap ); assembler;
  2485. var
  2486.     Plane,BMHeight:byte;
  2487.     LineInc:word;
  2488. asm
  2489.     push  ds
  2490.     cld
  2491.     mov   ax,SCREENSEG
  2492.     mov   es,ax
  2493.     mov   ax,Y
  2494.     mov   bx,ScrnLogicalByteWidth
  2495.     mul   bx
  2496.     mov   di,ScrnOffs
  2497.     add   di,ax
  2498.     mov   cx,X
  2499.     mov   dx,cx
  2500.     shr   dx,2
  2501.     add   di,dx
  2502.     lds   si,Bitmap
  2503.     lodsw
  2504.  
  2505.     mov   BMHeight,ah
  2506.     xor   ah,ah
  2507.     sub   bx,ax
  2508.     mov   LineInc,bx
  2509.     mov   bh,al
  2510.     and   cx,0003h
  2511.  
  2512.     mov   ah,11h
  2513.     shl   ah,cl
  2514.     mov   dx,SCINDEX
  2515.     mov   al,MAPMASK
  2516.     out   dx,al
  2517.     inc   dx
  2518.     mov   Plane,4
  2519. @@PlaneLoop:
  2520.     push  di
  2521.     mov   bl,BMHeight
  2522.     mov   al,ah
  2523.     out   dx,al
  2524. @@RowLoop:
  2525.     mov   cl,bh
  2526. @@ColLoop:
  2527.     lodsb
  2528.     or    al,al
  2529.     jz    @@NoPixel
  2530.     mov   es:[di],al
  2531. @@NoPixel:
  2532.     inc   di
  2533.     loop  @@ColLoop
  2534.     add   di,LineInc
  2535.     dec   bl
  2536.     jnz   @@RowLoop
  2537.     pop   di
  2538.     rol   ah,1
  2539.     adc   di,0
  2540.     dec   Plane
  2541.     jnz   @@PlaneLoop
  2542.     pop   ds
  2543. end;
  2544.  
  2545. Procedure XPutPbm( X,Y,ScrnOffs:word; var Bitmap ); assembler;
  2546. var
  2547.     Plane,BMHeight:byte;
  2548.     LineInc:word;
  2549. asm
  2550.     push  ds
  2551.     cld
  2552.     mov   ax,SCREENSEG
  2553.     mov   es,ax
  2554.     mov   ax,Y
  2555.     mov   bx,ScrnLogicalByteWidth
  2556.     mul   bx
  2557.     mov   di,ScrnOffs
  2558.     add   di,ax
  2559.     mov   cx,X
  2560.     mov   dx,cx
  2561.     shr   dx,2
  2562.     add   di,dx
  2563.  
  2564.     lds   si,Bitmap
  2565.     lodsw
  2566.     mov   BMHeight,ah
  2567.     xor   ah,ah
  2568.     sub   bx,ax
  2569.     mov   LineInc,bx
  2570.     mov   bh,al
  2571.  
  2572.     and   cx,0003h
  2573.  
  2574.     mov   ah,11h
  2575.     shl   ah,cl
  2576.     mov   dx,SCINDEX
  2577.     mov   al,MAPMASK
  2578.     out   dx,al
  2579.     inc   dx
  2580.     mov   [Plane],4
  2581. @@PlaneLoop:
  2582.     push  di
  2583.     mov   bl,BMHeight
  2584.     mov   al,ah
  2585.     out   dx,al
  2586. @@RowLoop:
  2587.     mov   cl,bh
  2588.     shr   cl,1
  2589.     rep   movsw
  2590.     adc   cl,0
  2591.     rep   movsb
  2592.     add   di,LineInc
  2593.     dec   bl
  2594.     jnz   @@RowLoop
  2595.     pop   di
  2596.     rol   ah,1
  2597.     adc   di,0
  2598.     dec   Plane
  2599.     jnz   @@PlaneLoop
  2600.     pop   ds
  2601. end;
  2602.  
  2603. Procedure XGetPbm( X,Y: word;SrcWidth,SrcHeight:byte;
  2604.                                      ScrnOffs:word; var Bitmap ); assembler;
  2605. var
  2606.     Plane:byte;
  2607.     LineInc:word;
  2608. asm
  2609.     push  ds
  2610.     cld
  2611.     mov   ax,Y
  2612.     mov   bx,ScrnLogicalByteWidth
  2613.     mul   bx
  2614.     mov   si,ScrnOffs
  2615.     add   si,ax
  2616.     mov   cx,X
  2617.     mov   dx,cx
  2618.     shr   dx,2
  2619.     add   si,dx
  2620.     mov   ax,SCREENSEG
  2621.     mov   ds,ax
  2622.     les   di,Bitmap
  2623.     mov   al,SrcWidth
  2624.     mov   ah,SrcHeight
  2625.     stosw
  2626.     xor   ah,ah
  2627.     sub   bx,ax
  2628.     mov   LineInc,bx
  2629.     mov   bh,al
  2630.     and   cx,0003h
  2631.     mov   ah,11h
  2632.     shl   ah,cl
  2633.     mov   dx,GCINDEX
  2634.     mov   al,READMAP
  2635.     out   dx,al
  2636.     inc   dx
  2637.     mov   Plane,4
  2638.     mov   al,cl
  2639. @@PlaneLoop:
  2640.     push  si
  2641.     mov   bl,SrcHeight
  2642.     out   dx,al
  2643. @@RowLoop:
  2644.     mov   cl,bh
  2645.     shr   cl,1
  2646.     rep   movsw
  2647.     adc   cl,0
  2648.     rep   movsb
  2649.     add   si,LineInc
  2650.     dec   bl
  2651.     jnz   @@RowLoop
  2652.     pop   si
  2653.     inc   al
  2654.     and   al,3
  2655.     rol   ah,1
  2656.     adc   si,0
  2657.     dec   Plane
  2658.     jnz   @@PlaneLoop
  2659.     pop   ds
  2660. end;
  2661.  
  2662. Procedure XCompilePbm( LogicalWidth : word; var bitmap,output ); assembler;
  2663. Var
  2664.     bwidth,scanx,scany,
  2665.     outputx,outputy,column,
  2666.     setcolumn,inputsize:word;
  2667. asm
  2668.     push ds
  2669.     mov word ptr scanx,0
  2670.     mov word ptr scany,0
  2671.     mov word ptr outputx,0
  2672.     mov word ptr outputy,0
  2673.     mov word ptr column,0
  2674.     mov word ptr setcolumn,0
  2675.     lds si,bitmap
  2676.     les di,output
  2677.     lodsb
  2678.     xor ah, ah
  2679.     mov bwidth, ax
  2680.     mov bl, al
  2681.     lodsb
  2682.     mul bl
  2683.     mov inputsize, ax
  2684.  
  2685. @@MainLoop:
  2686.     mov bx, scanx
  2687.     add bx, scany
  2688.     mov al, [si+bx]
  2689.     or  al, al
  2690.     jnz @@NoAdvance
  2691.     jmp @@Advance
  2692.  
  2693. @@NoAdvance:
  2694.     mov dx, setcolumn
  2695.     cmp dx, column
  2696.     je @@SameColumn
  2697.  
  2698. @@ColumnLoop:
  2699.     mov word ptr es:[di],RolAl
  2700.     add di,2
  2701.     mov word ptr es:[di],AdcSiImmed
  2702.     add di,2
  2703.     mov byte ptr es:[di],0
  2704.     inc di
  2705.     inc dx
  2706.     cmp dx, column
  2707.     jl @@ColumnLoop
  2708.     mov byte ptr es:[di],OUTAL
  2709.     inc di
  2710.     mov setcolumn, dx
  2711.  
  2712. @@SameColumn:
  2713.     mov dx, outputy
  2714.     add dx, outputx
  2715.     sub dx, 128
  2716.  
  2717.     inc word ptr scanx
  2718.     mov cx, scanx
  2719.     cmp cx, bwidth
  2720.     jge @@OnePixel
  2721.  
  2722.     inc word ptr outputx
  2723.     mov ah, [si+bx+1]
  2724.     or ah, ah
  2725.     jnz @@TwoPixels
  2726. @@OnePixel:
  2727.     cmp dx, 127
  2728.     jg @@OnePixLarge
  2729.     cmp dx, -128
  2730.     jl @@OnePixLarge
  2731.     mov word ptr es:[di],ShortStore8
  2732.     add di,2
  2733.     mov byte ptr es:[di],dl
  2734.     inc di
  2735.     jmp @@EmitOnePixel
  2736. @@OnePixLarge:
  2737.     mov word ptr es:[di],Store8
  2738.     add di,2
  2739.     mov word ptr es:[di],dx
  2740.     add di,2
  2741. @@EmitOnePixel:
  2742.     mov byte ptr es:[di],al
  2743.     inc di
  2744.     jmp @@Advance
  2745. @@TwoPixels:
  2746.     cmp dx, 127
  2747.     jg @@TwoPixLarge
  2748.     cmp dx, -128
  2749.     jl @@TwoPixLarge
  2750.     mov word ptr es:[di],ShortStore16
  2751.     add di,2
  2752.     mov byte ptr es:[di],dl
  2753.     inc di
  2754.     jmp @@EmitTwoPixels
  2755. @@TwoPixLarge:
  2756.     mov word ptr es:[di],Store16
  2757.     add di,2
  2758.     mov word ptr es:[di],dx
  2759.     add di,2
  2760. @@EmitTwoPixels:
  2761.     mov word ptr es:[di],ax
  2762.     add di,2
  2763.  
  2764. @@Advance:
  2765.     inc word ptr outputx
  2766.     mov ax, scanx
  2767.     inc ax
  2768.     cmp ax, bwidth
  2769.     jl @@AdvanceDone
  2770.     mov dx, outputy
  2771.     add dx, logicalwidth
  2772.     mov cx, scany
  2773.     add cx, bwidth
  2774.     cmp cx, inputsize
  2775.     jl @@NoNewColumn
  2776.     inc word ptr column
  2777.     mov cx, column
  2778.     cmp cx, 4
  2779.     je @@Exit
  2780.     xor cx, cx
  2781.     mov dx, cx
  2782.     add si, inputsize
  2783. @@NoNewColumn:
  2784.     mov outputy, dx
  2785.     mov scany, cx
  2786.     xor ax, ax
  2787.     mov word ptr outputx, 0
  2788. @@AdvanceDone:
  2789.     mov scanx, ax
  2790.     jmp @@MainLoop
  2791.  
  2792. @@Exit:
  2793.     mov byte ptr es:[di],Return
  2794.     inc di
  2795.     mov ax,di
  2796.     sub ax,word ptr output
  2797.     pop ds
  2798. end;
  2799.  
  2800. Function XSizeOfCPbm( logicalwidth : word; var bitmap ) : word; assembler;
  2801. var
  2802.     bwidth,scanx,scany,outputx,outputy,
  2803.     column,setcolumn,inputsize:word;
  2804. asm
  2805.     push ds
  2806.     mov word ptr scanx, 0
  2807.     mov word ptr scany, 0
  2808.     mov word ptr outputx, 0
  2809.     mov word ptr outputy, 0
  2810.     mov word ptr column, 0
  2811.     mov word ptr setcolumn, 0
  2812.     lds si,bitmap
  2813.     mov di, 1
  2814.     lodsb
  2815.     xor ah, ah
  2816.     mov bwidth, ax
  2817.     mov bl, al
  2818.     lodsb
  2819.     mul bl
  2820.     mov inputsize, ax
  2821.  
  2822. @@MainLoop:
  2823.     mov bx, scanx
  2824.     add bx, scany
  2825.  
  2826.     mov al, [si+bx]
  2827.     or  al, al
  2828.     jnz @@NoAdvance
  2829.     jmp @@Advance
  2830. @@NoAdvance:
  2831.  
  2832.     mov dx, setcolumn
  2833.     cmp dx, column
  2834.     je @@SameColumn
  2835. @@ColumnLoop:
  2836.     add di, 5
  2837.     inc dx
  2838.     cmp dx,column
  2839.     jl @@ColumnLoop
  2840.  
  2841.     inc di
  2842.     mov setcolumn, dx
  2843. @@SameColumn:
  2844.     mov dx, outputy
  2845.     add dx, outputx
  2846.     sub dx, 128
  2847.  
  2848.     inc word ptr scanx
  2849.     mov cx, scanx
  2850.     cmp cx, bwidth
  2851.     jge @@OnePixel
  2852.  
  2853.     inc word ptr outputx
  2854.     mov ah,[si+bx+1]
  2855.     or ah, ah
  2856.     jnz @@TwoPixels
  2857. @@OnePixel:
  2858.     cmp dx, 127
  2859.     jg @@OnePixLarge
  2860.     cmp dx, -128
  2861.     jl @@OnePixLarge
  2862.     add di, 4
  2863.     jmp @@EmitOnePixel
  2864. @@OnePixLarge:
  2865.     add di, 5
  2866. @@EmitOnePixel:
  2867.     jmp @@Advance
  2868. @@TwoPixels:
  2869.     cmp dx, 127
  2870.     jg @@TwoPixLarge
  2871.     cmp dx, -128
  2872.     jl @@TwoPixLarge
  2873.     add di, 5
  2874.     jmp @@EmitTwoPixels
  2875. @@TwoPixLarge:
  2876.     add di, 6
  2877. @@EmitTwoPixels:
  2878.  
  2879. @@Advance:
  2880.     inc word ptr outputx
  2881.     mov ax, scanx
  2882.     inc ax
  2883.     cmp ax, bwidth
  2884.     jl @@AdvanceDone
  2885.     mov dx, outputy
  2886.     add dx, logicalwidth
  2887.     mov cx, scany
  2888.     add cx, bwidth
  2889.     cmp cx, inputsize
  2890.     jl @@NoNewColumn
  2891.     inc word ptr column
  2892.     mov cx, column
  2893.     cmp cx, 4
  2894.     je @@Exit
  2895.     xor cx,cx
  2896.     mov dx,cx
  2897.     add si, inputsize
  2898. @@NoNewColumn:
  2899.     mov outputy, dx
  2900.     mov scany, cx
  2901.     xor ax, ax
  2902.     mov word ptr outputx, ax
  2903. @@AdvanceDone:
  2904.     mov scanx, ax
  2905.     jmp @@MainLoop
  2906.  
  2907. @@Exit:
  2908.     mov ax, di
  2909.     pop ds
  2910. end;
  2911.  
  2912. Procedure XCompileBitmap( logicalwidth:word; var bitmap, output ); assembler;
  2913. var
  2914.     bwidth,scanx,scany,outputx,outputy,
  2915.     column,setcolumn,inputsize:word;
  2916. asm
  2917.     push ds
  2918.     mov word ptr scanx,0
  2919.     mov word ptr scany,0
  2920.     mov word ptr outputx,0
  2921.     mov word ptr outputy,0
  2922.     mov word ptr column,0
  2923.     mov word ptr setcolumn,0
  2924.  
  2925.     lds si,bitmap
  2926.  
  2927.     les di,output
  2928.  
  2929.     lodsb
  2930.     xor ah, ah
  2931.     mov bwidth, ax
  2932.     mov bl, al
  2933.     lodsb
  2934.     mul bl
  2935.     mov inputsize, ax
  2936.  
  2937. @@MainLoop:
  2938.     mov bx, scanx
  2939.     add bx, scany
  2940.  
  2941.     mov al, [si+bx]
  2942.     or  al, al
  2943.     jnz @@NoAdvance
  2944.     jmp @@Advance
  2945. @@NoAdvance:
  2946.  
  2947.     mov dx, setcolumn
  2948.     cmp dx, column
  2949.     je @@SameColumn
  2950. @@ColumnLoop:
  2951.     mov word ptr es:[di],RolAl
  2952.     add di,2
  2953.     mov word ptr es:[di],AdcSiImmed
  2954.     add di,2
  2955.     mov byte ptr es:[di],0
  2956.     inc di
  2957.     inc dx
  2958.     cmp dx, column
  2959.     jl @@ColumnLoop
  2960.  
  2961.     mov byte ptr es:[di],OutAl
  2962.     inc di
  2963.     mov setcolumn, dx
  2964. @@SameColumn:
  2965.     mov dx, outputy
  2966.     add dx, outputx
  2967.     sub dx, 128
  2968.  
  2969.     add word ptr scanx, 4
  2970.     mov cx, scanx
  2971.     cmp cx, bwidth
  2972.     jge @@OnePixel
  2973.  
  2974.     inc word ptr outputx
  2975.     mov ah, [si+bx+4]
  2976.     or ah, ah
  2977.     jnz @@TwoPixels
  2978. @@OnePixel:
  2979.     cmp dx, 127
  2980.     jg @@OnePixLarge
  2981.     cmp dx, -128
  2982.     jl @@OnePixLarge
  2983.     mov word ptr es:[di],ShortStore8
  2984.     add di,2
  2985.     mov byte ptr es:[di],dl
  2986.     inc di
  2987.     jmp @@EmitOnePixel
  2988. @@OnePixLarge:
  2989.     mov word ptr es:[di],Store8
  2990.     add di,2
  2991.     mov word ptr es:[di],dx
  2992.     add di,2
  2993. @@EmitOnePixel:
  2994.     mov byte ptr es:[di],al
  2995.     inc di
  2996.     jmp @@Advance
  2997. @@TwoPixels:
  2998.     cmp dx, 127
  2999.     jg @@TwoPixLarge
  3000.     cmp dx, -128
  3001.     jl @@TwoPixLarge
  3002.     mov word ptr es:[di],ShortStore16
  3003.     add di,2
  3004.     mov byte ptr es:[di],dl
  3005.     inc di
  3006.     jmp @@EmitTwoPixels
  3007. @@TwoPixLarge:
  3008.     mov word ptr es:[di],Store16
  3009.     add di,2
  3010.     mov word ptr es:[di],dx
  3011.     add di,2
  3012. @@EmitTwoPixels:
  3013.     mov word ptr es:[di],ax
  3014.     add di,2
  3015.  
  3016. @@Advance:
  3017.     inc word ptr outputx
  3018.     mov ax, scanx
  3019.     add ax, 4
  3020.     cmp ax, bwidth
  3021.     jl @@AdvanceDone
  3022.     mov dx, outputy
  3023.     add dx, logicalwidth
  3024.     mov cx, scany
  3025.     add cx, bwidth
  3026.     cmp cx, inputsize
  3027.     jl @@NoNewColumn
  3028.     inc word ptr column
  3029.     mov cx, column
  3030.     cmp cx, 4
  3031.     je @@Exit
  3032.     xor cx, cx
  3033.     mov dx, cx
  3034. @@NoNewColumn:
  3035.     mov outputy, dx
  3036.     mov scany, cx
  3037.     mov word ptr outputx, 0
  3038.     mov ax,column
  3039. @@AdvanceDone:
  3040.     mov scanx, ax
  3041.     jmp @@MainLoop
  3042.  
  3043. @@Exit:
  3044.     mov byte ptr es:[di],Return
  3045.     inc di
  3046.     mov ax,di
  3047.     sub ax,word ptr output
  3048.     pop ds
  3049. end;
  3050.  
  3051.  
  3052. Function XSizeOfCBitmap( logicalwidth:word; var bitmap ):word; assembler;
  3053. var
  3054.     bwidth,scanx,scany,outputx,outputy,
  3055.     column,setcolumn,inputsize:word;
  3056. asm
  3057.     push ds
  3058.     mov word ptr scanx, 0
  3059.     mov word ptr scany, 0
  3060.     mov word ptr outputx, 0
  3061.     mov word ptr outputy, 0
  3062.     mov word ptr column, 0
  3063.     mov word ptr setcolumn, 0
  3064.     lds si,bitmap
  3065.  
  3066.     mov di, 1
  3067.  
  3068.     lodsb
  3069.     xor ah, ah
  3070.     mov bwidth, ax
  3071.     mov bl, al
  3072.     lodsb
  3073.     mul bl
  3074.     mov inputsize, ax
  3075.  
  3076. @@MainLoop:
  3077.     mov bx, scanx
  3078.     add bx, scany
  3079.  
  3080.     mov al, [si+bx]
  3081.     or  al, al
  3082.     jnz @@NoAdvance
  3083.     jmp @@Advance
  3084. @@NoAdvance:
  3085.  
  3086.     mov dx, setcolumn
  3087.     cmp dx, column
  3088.     je @@SameColumn
  3089. @@ColumnLoop:
  3090.     add di, 5
  3091.     inc dx
  3092.     cmp dx,column
  3093.     jl @@ColumnLoop
  3094.  
  3095.     inc di
  3096.     mov setcolumn, dx
  3097. @@SameColumn:
  3098.     mov dx, outputy
  3099.     add dx, outputx
  3100.     sub dx, 128
  3101.  
  3102.     add word ptr scanx, 4
  3103.     mov cx, scanx
  3104.     cmp cx, bwidth
  3105.     jge @@OnePixel
  3106.  
  3107.     inc word ptr outputx
  3108.     mov ah,[si+bx+4]
  3109.     or ah, ah
  3110.     jnz @@TwoPixels
  3111. @@OnePixel:
  3112.     cmp dx, 127
  3113.     jg @@OnePixLarge
  3114.     cmp dx, -128
  3115.     jl @@OnePixLarge
  3116.     add di, 4
  3117.     jmp @@EmitOnePixel
  3118. @@OnePixLarge:
  3119.     add di, 5
  3120. @@EmitOnePixel:
  3121.     jmp @@Advance
  3122. @@TwoPixels:
  3123.     cmp dx, 127
  3124.     jg @@TwoPixLarge
  3125.     cmp dx, -128
  3126.     jl @@TwoPixLarge
  3127.     add di, 5
  3128.     jmp @@EmitTwoPixels
  3129. @@TwoPixLarge:
  3130.     add di, 6
  3131. @@EmitTwoPixels:
  3132.  
  3133. @@Advance:
  3134.     inc word ptr outputx
  3135.     mov ax, scanx
  3136.     add ax,4
  3137.     cmp ax, bwidth
  3138.     jl @@AdvanceDone
  3139.     mov dx, outputy
  3140.     add dx, logicalwidth
  3141.     mov cx, scany
  3142.     add cx, bwidth
  3143.     cmp cx, inputsize
  3144.     jl @@NoNewColumn
  3145.     inc word ptr column
  3146.     mov cx, column
  3147.     cmp cx, 4
  3148.     je @@Exit
  3149.     xor cx,cx
  3150.     mov dx,cx
  3151. @@NoNewColumn:
  3152.     mov outputy, dx
  3153.     mov scany, cx
  3154.     mov word ptr outputx, 0
  3155.     mov ax,column
  3156.  
  3157. @@AdvanceDone:
  3158.     mov scanx, ax
  3159.     jmp @@MainLoop
  3160.  
  3161. @@Exit:
  3162.     mov ax, di
  3163.     pop ds
  3164. end;
  3165.  
  3166.  
  3167. Procedure XPutCBitmap( XPos,YPos,PageOffset:word; var Sprite ); assembler;
  3168. asm
  3169.     push ds
  3170.  
  3171.     mov ax, ScrnLogicalByteWidth
  3172.     mul word ptr YPos
  3173.     mov si, XPos
  3174.     mov bx, si
  3175.     sar si, 2
  3176.     add si, ax
  3177.     add si, PageOffset
  3178.     add si, 128
  3179.     and bx, 3
  3180.     mov ah, byte ptr ColumnMask[bx]
  3181.     mov dx, SCINDEX
  3182.     mov al, MAPMASK
  3183.     out dx, ax
  3184.     inc dx
  3185.     mov al, ah
  3186.     mov bx, SCREENSEG
  3187.     mov ds, bx
  3188.     call Sprite
  3189.     pop ds
  3190. end;
  3191.  
  3192. Procedure XGetPalStruc( var PalBuff; NumColors,StartColor:word ); assembler;
  3193. asm
  3194.     cld
  3195.     les  di,PalBuff
  3196.     mov  si,StartColor
  3197.     mov  ax,si
  3198.     stosb
  3199.     mov  dx,NumColors
  3200.     mov  al,dl
  3201.     stosb
  3202.     mov  cx,dx
  3203.     cld
  3204.     mov  dx,INPUTSTATUS0
  3205. @@WaitNotVsync:
  3206.     in   al,dx
  3207.     test al,08h
  3208.     jnz  @@WaitNotVsync
  3209. @@WaitVsync:
  3210.     in   al,dx
  3211.     test al,08h
  3212.     jz   @@WaitVsync
  3213.     mov  ax, si
  3214.     mov  dx, DACREADINDEX
  3215.     cli
  3216.     out  dx, al
  3217.     mov  dx, DACDATA
  3218.     mov  bx, cx
  3219.     shl  bx, 1
  3220.     add  cx, bx
  3221.     rep  insb
  3222.     sti
  3223. end;
  3224.  
  3225. Procedure XGetPalRaw( Var PalBuff; NumColors,StartColor:word ); assembler;
  3226. asm
  3227.     les  di,PalBuff
  3228.     mov  si,StartColor
  3229.     mov  cx,NumColors
  3230. @@ReadPalEntry:
  3231.     cld
  3232.     mov     dx,INPUTSTATUS0
  3233. @@WaitNotVsync:
  3234.     in      al,dx
  3235.     test    al,08h
  3236.     jnz     @@WaitNotVsync
  3237. @@WaitVsync:
  3238.     in      al,dx
  3239.     test    al,08h
  3240.     jz      @@WaitVsync
  3241.     mov  ax,si
  3242.     mov  dx,DACREADINDEX
  3243.     cli
  3244.     out  dx,al
  3245.     mov  dx,DACDATA
  3246.     mov  bx,cx
  3247.     shl  bx,1
  3248.     add  cx,bx
  3249.     rep  insb
  3250.     sti
  3251. end;
  3252.  
  3253.  
  3254. Procedure XPutPalStruc( Var CompPalBuff ); assembler;
  3255. asm
  3256.     push ds
  3257.     cld
  3258.     lds  si,CompPalBuff
  3259.     lodsb
  3260.     mov  ah,0
  3261.     mov  bx,ax
  3262.     lodsb
  3263.     mov  ah,0
  3264.     mov     cx,ax
  3265.     or   cx,cx
  3266.     jz   @@Done
  3267.     cld
  3268.     mov  dx,INPUTSTATUS0
  3269. @@WaitNotVsync:
  3270.     in   al,dx
  3271.     test al,08h
  3272.     jnz  @@WaitNotVsync
  3273. @@WaitVsync:
  3274.     in   al,dx
  3275.     test al,08h
  3276.     jz   @@WaitVsync
  3277.     mov  ax,bx
  3278.     mov  bx,60
  3279. @@SetLoop:
  3280.     mov  dx,DACWRITEINDEX
  3281.     out  dx,al
  3282.     mov  dx,DACDATA
  3283.     outsb
  3284.     outsb
  3285.     outsb
  3286.     inc  al
  3287.     dec  bx
  3288.     js   @@testvsync
  3289.     loop @@SetLoop
  3290.     jmp  @@Done
  3291. @@testvsync:
  3292.     mov  dx,INPUTSTATUS0
  3293.     push ax
  3294. @@Wait:
  3295.     in   al,dx
  3296.     test al,08h
  3297.     jz   @@Wait
  3298.     pop  ax
  3299.     mov  bx,60
  3300.     loop @@SetLoop
  3301. @@Done:
  3302.     pop ds
  3303. end;
  3304.  
  3305. Procedure XTransposePalStruc( Var CompPalBuff; StartColor:word ); assembler;
  3306. asm
  3307.     push ds
  3308.     cld
  3309.     lds  si,CompPalBuff
  3310.     mov  bx,StartColor
  3311.     mov  [si],bl
  3312.     inc  si
  3313.     lodsb
  3314.     mov  ah,0
  3315.     mov    cx,ax
  3316.     or   cx,cx
  3317.     jz   @@Done
  3318.     ;cli
  3319.     cld
  3320.     mov  dx,INPUTSTATUS0
  3321. @@WaitNotVsync:
  3322.     in   al,dx
  3323.     test al,08h
  3324.     jnz  @@WaitNotVsync
  3325. @@WaitVsync:
  3326.     in   al,dx
  3327.     test al,08h
  3328.     jz   @@WaitVsync
  3329.     mov  ax,bx
  3330.     mov  bx,60
  3331. @@SetLoop:
  3332.     mov  dx,DACWRITEINDEX
  3333.     out  dx,al
  3334.     mov  dx,DACDATA
  3335.     outsb
  3336.     outsb
  3337.     outsb
  3338.     inc  al
  3339.     dec  bx
  3340.     js   @@testvsync
  3341.     loop @@SetLoop
  3342.     jmp  @@Done
  3343. @@testvsync:
  3344.     mov  dx,INPUTSTATUS0
  3345.     push ax
  3346. @@Wait:
  3347.     in   al,dx
  3348.     test al,08h
  3349.     jz   @@Wait
  3350.     pop  ax
  3351.     mov  bx,60
  3352.     loop @@SetLoop
  3353. @@Done:
  3354.     pop ds
  3355. end;
  3356.  
  3357.  
  3358. Procedure XPutPalRaw( Var PalBuff; NumColors,StartColor:word ); assembler;
  3359. asm
  3360.     push ds
  3361.     mov  cx,NumColors
  3362.     mov  bx,StartColor
  3363.     lds  si,PalBuff
  3364. @@WritePalEntry:
  3365.     or   cx,cx
  3366.     jz   @@Done
  3367.     cli
  3368.     cld
  3369.     mov  dx,INPUTSTATUS0
  3370. @@WaitNotVsync:
  3371.     in   al,dx
  3372.     test al,08h
  3373.     jnz  @@WaitNotVsync
  3374. @@WaitVsync:
  3375.     in   al,dx
  3376.     test al,08h
  3377.     jz   @@WaitVsync
  3378.     mov  ax,bx
  3379.     mov  bx,60
  3380. @@SetLoop:
  3381.     mov  dx,DACWRITEINDEX
  3382.     out  dx,al
  3383.     mov  dx,DACDATA
  3384.     outsb
  3385.     outsb
  3386.     outsb
  3387.     inc  al
  3388.     dec  bx
  3389.     js   @@testvsync
  3390.     loop @@SetLoop
  3391.     jmp  @@Done
  3392. @@testvsync:
  3393.     mov     dx,INPUTSTATUS0
  3394.     push    ax
  3395. @@Wait:
  3396.     in      al,dx
  3397.     test    al,08h
  3398.     jz      @@Wait
  3399.     pop     ax
  3400.     mov     bx,60
  3401.     loop @@SetLoop
  3402. @@Done:
  3403.     sti
  3404.     pop  ds
  3405. end;
  3406.  
  3407.  
  3408. Procedure XSetRGB( ColorIndex,R,G,B:byte ); assembler;
  3409. asm
  3410.     mov  al,ColorIndex
  3411.     mov  dx,DACWRITEINDEX
  3412.     out  dx,al
  3413.     mov  dx,DACDATA
  3414.     mov  al,R
  3415.     out  dx,al
  3416.     mov  al,G
  3417.     out  dx,al
  3418.     mov  al,B
  3419.     out  dx,al
  3420. end;
  3421.  
  3422. Procedure XRotPalStruc( Var PalBuff; Direction:word ); assembler;
  3423. asm
  3424.     push ds
  3425.     cld
  3426.     lds     si,PalBuff
  3427.     lodsw
  3428.     xor  ch,ch
  3429.     mov  cl,ah
  3430.     mov     ax,ds
  3431.     mov     es,ax
  3432.     dec  cx
  3433.     mov     bx,cx
  3434.     shl     bx,1
  3435.     add  cx,bx
  3436.     cmp  Direction,0
  3437.     jne  @@forward
  3438.     std
  3439.     add  si,cx
  3440.     add  si,2
  3441. @@forward:
  3442.     mov     ax,si
  3443.     mov     di,ax
  3444.     lodsb
  3445.     mov  dl,al
  3446.     lodsb
  3447.     mov  dh,al
  3448.     lodsb
  3449.     mov  bl,al
  3450.     rep     movsb
  3451.     mov  al,dl
  3452.     stosb
  3453.     mov  al,dh
  3454.     stosb
  3455.     mov  al,bl
  3456.     stosb
  3457.     pop     ds
  3458. end;
  3459.  
  3460.  
  3461. Procedure XRotPalRaw( Var PalBuff; Direction, NumColors:word ); assembler;
  3462. asm
  3463.     push ds
  3464.     cld
  3465.     mov     cx,NumColors
  3466.     lds     si,PalBuff
  3467. @@RotatePalEntry:
  3468.     mov     ax,ds
  3469.     mov     es,ax
  3470.     dec  cx
  3471.     mov     bx,cx
  3472.     shl     bx,1
  3473.     add  cx,bx
  3474.     cmp  Direction,0
  3475.     jne  @@forward
  3476.     std
  3477.     add  si,cx
  3478.     add  si,2
  3479. @@forward:
  3480.     mov     ax,si
  3481.     mov     di,ax
  3482.     lodsb
  3483.     mov  dl,al
  3484.     lodsb
  3485.     mov  dh,al
  3486.     lodsb
  3487.     mov  bl,al
  3488.     rep     movsb
  3489.     mov  al,dl
  3490.     stosb
  3491.     mov  al,dh
  3492.     stosb
  3493.     mov  al,bl
  3494.     stosb
  3495.     pop     ds
  3496. end;
  3497.  
  3498. Function XCpContrastPalStruc( Var PalSrcBuff,PalDestBuff;
  3499.                                                                 Intensity:byte ):word; assembler;
  3500. asm
  3501.     push ds
  3502.     cld
  3503.     mov  bh,0ffh
  3504.     sub  bh,Intensity
  3505.     and  bh,07fh
  3506.     lds     si,PalSrcBuff
  3507.     les     di,PalDestBuff
  3508.     lodsw
  3509.     stosw
  3510.     xor  ch,ch
  3511.     mov  cl,ah
  3512.     mov  dx,0
  3513. @@MainLoop:
  3514.     lodsw
  3515.     sub  al,bh
  3516.     jns  @@DecrementOKR
  3517.     xor  al,al
  3518. @@DecrementOKR:
  3519.     sub  ah,bh
  3520.     jns  @@DecrementOKG
  3521.     xor  ah,ah
  3522. @@DecrementOKG:
  3523.     or   dx,ax
  3524.     or   dl,ah
  3525.     stosw
  3526.     lodsb
  3527.     sub  al,bh
  3528.     jns  @@DecrementOKB
  3529.     xor  al,al
  3530. @@DecrementOKB:
  3531.     or   dl,al
  3532.     stosb
  3533.     loop @@MainLoop
  3534.     mov  ax,dx
  3535.     pop     ds
  3536. end;
  3537.  
  3538.  
  3539. Procedure XPutContrastPalStruc( Var CompPalBuff; Intensity:byte ); assembler;
  3540. asm
  3541.     push    ds
  3542.     cld
  3543.     mov     bh,0ffh
  3544.     sub     bh,Intensity
  3545.     and     bh,07fh
  3546.     mov     di,40
  3547.     lds     si,CompPalBuff
  3548.     lodsb
  3549.     mov     bl,al
  3550.     lodsb
  3551.     mov     ah,0
  3552.     mov    cx,ax
  3553.     or      cx,cx
  3554.     jz      @@Done
  3555.  
  3556.     mov     dx,INPUTSTATUS0
  3557. @@WaitNotVsync:
  3558.     in      al,dx
  3559.     test    al,08h
  3560.     jnz     @@WaitNotVsync
  3561. @@WaitVsync:
  3562.     in      al,dx
  3563.     test    al,08h
  3564.     jz      @@WaitVsync
  3565.  
  3566. @@MainLoop:
  3567.     mov  al,bl
  3568.     mov  dx,DACWRITEINDEX
  3569.     out  dx,al
  3570.     inc  dx
  3571.     lodsb
  3572.     sub  al,bh
  3573.     jns  @@DecrementOKR
  3574.     xor  al,al
  3575. @@DecrementOKR:
  3576.     out  dx,al
  3577.  
  3578.     lodsb
  3579.     sub  al,bh
  3580.     jns  @@DecrementOKG
  3581.     xor  al,al
  3582. @@DecrementOKG:
  3583.     out  dx,al
  3584.  
  3585.     lodsb
  3586.     sub  al,bh
  3587.     jns  @@DecrementOKB
  3588.     xor  al,al
  3589. @@DecrementOKB:
  3590.     out  dx,al
  3591.  
  3592.     inc  bl
  3593.     dec  di
  3594.     js   @@testvsync
  3595.     loop @@MainLoop
  3596.     jmp  @@Done
  3597.  
  3598.  
  3599. @@testvsync:
  3600.     mov     dx,INPUTSTATUS0
  3601.     push    ax
  3602. @@Wait:
  3603.     in      al,dx
  3604.     test    al,08h
  3605.     jz      @@Wait
  3606.     pop     ax
  3607.     mov     di,40
  3608.     loop    @@MainLoop
  3609. @@Done:
  3610.     ;sti
  3611.     pop  ds
  3612. end;
  3613.  
  3614. Procedure XTextInit; assembler;
  3615. asm
  3616.     push bp
  3617.     mov  FontDriverActive,1
  3618.     mov  ax,1130h
  3619.     push ax
  3620.     mov  bh,3
  3621.     int  10h
  3622.     mov  word ptr F8x8Ptr,bp
  3623.     mov  word ptr F8x8Ptr+2,es
  3624.  
  3625.     mov  word ptr FontPtr,bp
  3626.     mov  word ptr FontPtr+2,es
  3627.  
  3628.     pop  ax
  3629.     mov  bh,2
  3630.     int  10h
  3631.     mov  word ptr F8x14Ptr,bp
  3632.     mov  word ptr F8x14Ptr+2,es
  3633.  
  3634.  
  3635.     mov  al,8
  3636.     mov  CharHeight,al
  3637.     mov  CharWidth ,al
  3638.  
  3639.     mov  dx,offset MirrorTable
  3640.     mov  MirrorTableOffs,dx
  3641.     pop  bp
  3642. end;
  3643.  
  3644.  
  3645. Procedure XSetFont( FontID : word ); assembler;
  3646. asm
  3647.     xor  dx,dx
  3648.     mov  cx,FontID
  3649.     cmp  cx,2
  3650.  
  3651.     jne  @@notuserfont
  3652.     mov  ax,word ptr UserFontPtr
  3653.     mov  word ptr FontPtr,ax
  3654.  
  3655.     mov  ax,word ptr UserFontPtr+2
  3656.     mov  word ptr FontPtr+2,ax
  3657.  
  3658.     mov  al,UserChHeight
  3659.     mov  CharHeight,al
  3660.  
  3661.     mov  al,UserChWidth
  3662.     mov  CharWidth,al
  3663.  
  3664.     mov  al,UserFirstCh
  3665.     mov  FirstChar,al
  3666.     jmp  @@done
  3667.  
  3668. @@notuserfont:
  3669.  
  3670.     mov  dx,offset MirrorTable
  3671.     mov  CharWidth,8
  3672.     mov  FirstChar,0
  3673.     cmp  cx,1
  3674.     jne  @@not8x14font
  3675.  
  3676.     mov  ax,word ptr F8x14Ptr
  3677.     mov  word ptr FontPtr,ax
  3678.  
  3679.     mov  ax,word ptr F8x14Ptr+2
  3680.     mov  word ptr FontPtr+2,ax
  3681.  
  3682.     mov  CharHeight,14
  3683.     jmp  @@done
  3684.  
  3685. @@not8x14font:
  3686.     mov  ax,word ptr F8x8Ptr
  3687.     mov  word ptr FontPtr,ax
  3688.  
  3689.     mov  ax,word ptr F8x8Ptr+2
  3690.     mov  word ptr FontPtr+2,ax
  3691.  
  3692.     mov  CharHeight,8
  3693.  
  3694. @@done:
  3695.     mov  MirrorTableOffs,dx
  3696. end;
  3697.  
  3698. Procedure XRegisterUserFont( var FontToRegister ); assembler;
  3699. asm
  3700.     mov  ax,word ptr FontToRegister
  3701.     mov  bx,word ptr FontToRegister+2
  3702.     add  ax,4
  3703.     mov  word ptr UserFontPtr,ax
  3704.     mov  word ptr UserFontPtr+2,bx
  3705.  
  3706.     push ds
  3707.     lds  si,FontToRegister
  3708.     lodsw
  3709.     mov  bx,ax
  3710.     lodsw
  3711.     pop  ds
  3712.     mov  UserChHeight,al
  3713.     mov  UserChWidth,ah
  3714.     mov  UserFirstCh,bl
  3715. end;
  3716.  
  3717. function XGetCharWidth( ACh : char ) : byte; assembler;
  3718. asm
  3719.     xor  ah,ah
  3720.     mov  al,CharWidth
  3721.     or   al,al
  3722.     jz   @@NotFixed
  3723.     jmp  @@Done
  3724.  
  3725. @@NotFixed:
  3726.     push si
  3727.     mov  al,CharHeight
  3728.     mov  bx,ax
  3729.     inc  al
  3730.     mov  dl, ACh
  3731.     sub  dl,FirstChar
  3732.     mul  dl
  3733.     add  ax,bx
  3734.     les  si,dword ptr FontPtr
  3735.     add  si,ax
  3736.     xor  ah,ah
  3737.     mov  al,byte ptr es:[si]
  3738. @@Done:
  3739. end;
  3740.  
  3741. function XCharPut( Chr:char; X, Y, ScrnOffs, Color:word ) : byte; assembler;
  3742. var
  3743.     ScreenInc,
  3744.     Hold:word;
  3745. asm
  3746.     push ds
  3747.     cld
  3748.     mov  ax,ScrnLogicalByteWidth
  3749.     mov  bx,ax
  3750.     sub  bx,3
  3751.     mov  ScreenInc,bx
  3752.     mul  Y
  3753.     mov  di,X
  3754.     mov  cx,di
  3755.     shr  di,2
  3756.     add  di,ax
  3757.     add  di,ScrnOffs
  3758.  
  3759.     mov  ax,SCREENSEG
  3760.     mov  es,ax
  3761.  
  3762.     and  cx,3
  3763.  
  3764.     mov  bx,MirrorTableOffs
  3765.     mov  al,CharHeight
  3766.     xor  ah,ah
  3767.     mov  ch,al
  3768.  
  3769.     cmp  CharWidth,0
  3770.     jne  @@NoWidthByte
  3771.     inc  al
  3772.  
  3773. @@NoWidthByte:
  3774.     mov  dl,Chr
  3775.     sub  dl,FirstChar
  3776.     mul  dl
  3777.     lds  si,dword ptr FontPtr
  3778.     add  si,ax
  3779.  
  3780.     mov  dx,SCINDEX
  3781.  
  3782. @@MainLoop:
  3783.  
  3784.     lodsb
  3785.     or   al,al
  3786.     jz   @@NoCharPixels
  3787.  
  3788.     or   bx,bx
  3789.     jz   @@DontMirror
  3790.     push ds
  3791.     mov  dx,seg @data
  3792.     mov  ds,dx
  3793.     xlat
  3794.     pop  ds
  3795.     mov  dx,SCINDEX
  3796.  
  3797. @@DontMirror:
  3798.     xor  ah,ah
  3799.     shl  ax,cl
  3800.     mov  Hold,ax
  3801.  
  3802.     mov  ah,al
  3803.     and  ah,0fh
  3804.     jnz  @@p1
  3805.     inc  di
  3806.     jmp  @@SecondNibble
  3807.  
  3808. @@p1:
  3809.     mov  al,MAPMASK
  3810.     out  dx,ax
  3811.     mov  al,byte ptr Color
  3812.     stosb
  3813.  
  3814. @@SecondNibble:
  3815.     mov  ax,Hold
  3816.     shl  ax,4
  3817.     and  ah,0fh
  3818.     jnz  @@p2
  3819.     inc  di
  3820.     jmp  @@ThirdNibble
  3821.  
  3822. @@p2:
  3823.     mov  al,MAPMASK
  3824.     out  dx,ax
  3825.     mov  al,byte ptr Color
  3826.     stosb
  3827.  
  3828. @@ThirdNibble:
  3829.     mov  ax,Hold
  3830.     and  ah,0fh
  3831.     jnz  @@p3
  3832.     inc  di
  3833.     jmp  @@NextCharRow
  3834.  
  3835. @@p3:
  3836.     mov  al,MAPMASK
  3837.     out  dx,ax
  3838.     mov  al,byte ptr Color
  3839.     stosb
  3840.  
  3841. @@NextCharRow:
  3842.     add  di,ScreenInc
  3843.     dec  ch
  3844.     jnz  @@MainLoop
  3845.  
  3846. @@done:
  3847.     pop  es
  3848.     mov  ah,0
  3849.     mov  al,es:CharWidth
  3850.     or   al,al
  3851.     jnz  @@FixedSpacing
  3852.     lodsb
  3853. @@FixedSpacing:
  3854.  
  3855.     mov  bx,es
  3856.     mov  ds,bx
  3857.     jmp @@TheEnd
  3858.  
  3859.  
  3860. @@NoCharPixels:
  3861.     add  di,3
  3862.     add  di,ScreenInc
  3863.     dec  ch
  3864.     jnz  @@MainLoop
  3865.     jmp  @@done
  3866.  
  3867. @@TheEnd:
  3868.  
  3869. end;
  3870.  
  3871. Procedure XPrintf( x, y, ScrnOffs, Color : word; s : string );
  3872. var
  3873.     i : integer;
  3874. begin
  3875.     for i := 1 to length(s) do
  3876.         x:=x+XCharPut( s[i], x, y, ScrnOffs, color );
  3877. end;
  3878.  
  3879. Procedure XBgPrintf( x, y, ScrnOffs, fgcolor, bgcolor : word; s : string );
  3880. var
  3881.     i : integer;
  3882. begin
  3883.     for i := 1 to length(s) do
  3884.     begin
  3885.         XRectFill( x, y, x+XGetCharWidth(s[i]),y+CharHeight,ScrnOffs,bgcolor);
  3886.         x := x + XCharPut( s[i], x, y, ScrnOffs, fgcolor);
  3887.     end;
  3888.  
  3889. end;
  3890.  
  3891.  
  3892. procedure HLineClipR; near; assembler;
  3893. asm
  3894.     push    di
  3895.     cmp     dx,ax
  3896.     jl      @@Invisible
  3897.  
  3898.     cmp     cx,TopClip
  3899.     jl      @@Invisible
  3900.  
  3901.     cmp     cx,BottomClip
  3902.     jg      @@Invisible
  3903.  
  3904.     mov     di,RightClip
  3905.     sal     di,2
  3906.     cmp     ax,di
  3907.     jg      @@Invisible
  3908.     cmp     dx,di
  3909.     jle     @@ClipLeft
  3910.     mov     dx,di
  3911.  
  3912. @@ClipLeft:
  3913.     mov     di,LeftClip
  3914.     sal     di,2
  3915.     cmp     dx,di
  3916.     jl      @@Invisible
  3917.     cmp     ax,di
  3918.     jge     @@DoLine
  3919.     mov     ax,di
  3920.     jmp     @@DoLine
  3921.  
  3922. @@Invisible:
  3923.     pop     di
  3924.     ret
  3925.  
  3926. @@DoLine:
  3927.     pop     di
  3928.     xchg    cx,ax
  3929.     mov     si,dx
  3930.     mul     ScrnLogicalByteWidth
  3931.     mov     dx,si
  3932.     add     ax,di
  3933.     mov     di,cx
  3934.     sar     di,2
  3935.     add     di,ax
  3936.     and     si,03h
  3937.     mov     ah,byte ptr RightClipPlaneMask[si]
  3938.     mov     si,cx
  3939.     and     si,03h
  3940.     mov     al,byte ptr LeftClipPlaneMask[si]
  3941.     cmp     dx,cx
  3942.     jle     @@Invisible2
  3943.     xchg    cx,dx
  3944.     dec     cx
  3945.     and     dx,not 03h
  3946.     sub     cx,dx
  3947.     js      @@Invisible2
  3948.     shr     cx,2
  3949.     jnz     @@MasksSet
  3950.     and     al,ah
  3951. @@MasksSet:
  3952.     mov     dl,bl
  3953.     mov     bx,ax
  3954.     mov     ah,dl
  3955.     mov     dx,SCINDEX+1
  3956.     mov     al,bl
  3957.     out     dx,al
  3958.     mov     al,ah
  3959.     stosb
  3960.     dec     cx
  3961.     js      @@Invisible2
  3962.     jz      @@RightEnd
  3963.     mov     al,0fh
  3964.     out     dx,al
  3965.     mov     al,ah
  3966.     shr     cx,1
  3967.     rep     stosw
  3968.     adc     cx,cx
  3969.     rep     stosb
  3970.  
  3971. @@RightEnd:
  3972.     mov     al,bh
  3973.     out     dx,al
  3974.     mov     al,ah
  3975.     stosb
  3976. @@Invisible2:
  3977.     ret
  3978. end;
  3979.  
  3980. Procedure XTriangle( X0, Y0, X1, Y1, X2, Y2, Color, PageOffset:word ); assembler;
  3981. var
  3982.     DX01, DY01, DX02, DY02, DX12, DY12,    DP01, DP02, DP12, XA01, XA02, XA12 : word;
  3983. asm
  3984.     push         di
  3985.     push    es
  3986.     push    ds
  3987.     mov     ax,X0
  3988.     mov     bx,Y0
  3989.     mov     cx,X1
  3990.     mov     dx,Y1
  3991.     cmp     bx,dx
  3992.     jl      @@triY0lY1
  3993.     je      @@triY0eY1
  3994.     xchg    ax,cx
  3995.     xchg    bx,dx
  3996.  
  3997. @@triY0lY1:
  3998.     cmp     dx,Y2
  3999.     jg      @@tria
  4000.     jmp     @@trisorted
  4001. @@tria:
  4002.     xchg    cx,X2
  4003.     xchg    dx,Y2
  4004.     cmp     bx,dx
  4005.     jge     @@trib
  4006.     jmp     @@trisorted
  4007. @@trib:
  4008.     je      @@tribot
  4009.     xchg    ax,cx
  4010.     xchg    bx,dx
  4011.     jmp     @@trisorted
  4012. @@triY0eY1:
  4013.     cmp     bx,Y2
  4014.     jl      @@tribot
  4015.     jg      @@tric
  4016.     jmp     @@tridone
  4017. @@tric:
  4018.     xchg    ax,X2
  4019.     xchg    bx,Y2
  4020.     jmp     @@trisorted
  4021.  
  4022. @@tribot:
  4023.     cmp     ax,cx
  4024.     jl      @@tribotsorted
  4025.     jg      @@tribota
  4026.     jmp     @@tridone
  4027. @@tribota:
  4028.     xchg    ax,cx
  4029. @@tribotsorted:
  4030.     cmp     bx,BottomClip
  4031.     jle     @@triboty0ok
  4032.     jmp     @@tridone
  4033. @@triboty0ok:
  4034.     mov     si,Y2
  4035.     cmp     si,TopClip
  4036.     jge     @@triboty2ok
  4037.     jmp     @@tridone
  4038. @@triboty2ok:
  4039.     mov     X0,ax
  4040.     mov     Y0,bx
  4041.     mov     X1,cx
  4042.     mov     Y1,dx
  4043.  
  4044.     mov     bx,Y2
  4045.     sub     bx,Y0
  4046.     mov     DY02,bx
  4047.     mov     ax,X2
  4048.     sub     ax,X0
  4049.     mov     DX02,ax
  4050.     mov     cx,ax
  4051.     cwd
  4052.     idiv    bx
  4053.     cmp     cx,0
  4054.     jge     @@tribot02
  4055.     dec     ax
  4056. @@tribot02:
  4057.     mov     XA02,ax
  4058.     imul    bx
  4059.     sub     cx,ax
  4060.     mov     DP02,cx
  4061.  
  4062.     mov     bx,Y2
  4063.     sub     bx,Y1
  4064.     mov     DY12,bx
  4065.     mov     ax,X2
  4066.     sub     ax,X1
  4067.     mov     DX12,ax
  4068.     mov     cx,ax
  4069.     cwd
  4070.     idiv    bx
  4071.     cmp     cx,0
  4072.     jge     @@tribot12
  4073.     dec     ax
  4074. @@tribot12:
  4075.     mov     XA12,ax
  4076.     imul    bx
  4077.     sub     cx,ax
  4078.     mov     DP12,cx
  4079.  
  4080.     mov     ax,0
  4081.     mov     bx,0
  4082.     mov     cx,Y0
  4083.     mov     si,X0
  4084.     mov     di,X1
  4085.     dec     di
  4086. @@tribotloop:
  4087.     inc     cx
  4088.  
  4089.     add     ax,DP02
  4090.     jle     @@tribotshortl
  4091.     sub     ax,DY02
  4092.     inc     si
  4093. @@tribotshortl:
  4094.     add     si,XA02
  4095.  
  4096.     add     bx,DP12
  4097.     jle     @@tribotshortr
  4098.     sub     bx,DY12
  4099.     inc     di
  4100. @@tribotshortr:
  4101.     add     di,XA12
  4102.  
  4103.     push    di
  4104.     push    si
  4105.     cmp     cx,Y2
  4106.     jl      @@tribotloop
  4107.  
  4108.     jmp     @@tridrawlines
  4109.  
  4110.  
  4111. @@trisorted:
  4112.     cmp     bx,BottomClip
  4113.     jle     @@triy0ok
  4114.     jmp     @@tridone
  4115. @@triy0ok:
  4116.     mov     si,Y2
  4117.     cmp     si,TopClip
  4118.     jge     @@triy2ok
  4119.     jmp     @@tridone
  4120. @@triy2ok:
  4121.     mov     X0,ax
  4122.     mov     Y0,bx
  4123.     mov     X1,cx
  4124.     mov     Y1,dx
  4125.  
  4126.     mov     bx,dx
  4127.     sub     bx,Y0
  4128.     mov     DY01,bx
  4129.     mov     ax,X1
  4130.     sub     ax,X0
  4131.     mov     DX01,ax
  4132.     mov     cx,ax
  4133.     cwd
  4134.     idiv    bx
  4135.     cmp     cx,0
  4136.     jge     @@tripsl01
  4137.     dec     ax
  4138. @@tripsl01:
  4139.     mov     XA01,ax
  4140.     imul    bx
  4141.     sub     cx,ax
  4142.     mov     DP01,cx
  4143.  
  4144.     mov     bx,Y2
  4145.     sub     bx,Y0
  4146.     mov     DY02,bx
  4147.     mov     ax,X2
  4148.     sub     ax,X0
  4149.     mov     DX02,ax
  4150.     mov     cx,ax
  4151.     cwd
  4152.     idiv    bx
  4153.     cmp     cx,0
  4154.     jge     @@tripsl02
  4155.     dec     ax
  4156. @@tripsl02:
  4157.     mov     XA02,ax
  4158.     imul    bx
  4159.     sub     cx,ax
  4160.     mov     DP02,cx
  4161.  
  4162.     mov     bx,Y2
  4163.     sub     bx,Y1
  4164.     jle     @@triconstcomputed
  4165.     mov     DY12,bx
  4166.     mov     ax,X2
  4167.     sub     ax,X1
  4168.     mov     DX12,ax
  4169.     mov     cx,ax
  4170.     cwd
  4171.     idiv    bx
  4172.     cmp     cx,0
  4173.     jge     @@tripsl12
  4174.     dec     ax
  4175. @@tripsl12:
  4176.     mov     XA12,ax
  4177.     imul    bx
  4178.     sub     cx,ax
  4179.     mov     DP12,cx
  4180.  
  4181. @@triconstcomputed:
  4182.     mov     ax,DX01
  4183.     imul    word ptr DY02
  4184.     mov     bx,ax
  4185.     mov     cx,dx
  4186.  
  4187.     mov     ax,DX02
  4188.     imul    word ptr DY01
  4189.     cmp     cx,dx
  4190.     jg      @@tript1rt
  4191.     jl      @@tript1lt
  4192.     cmp     bx,ax
  4193.     ja      @@tript1rt
  4194.     jb      @@tript1lt
  4195.     jmp     @@tridone
  4196.  
  4197. @@tript1lt:
  4198.     mov     ax,0
  4199.     mov     bx,0
  4200.     mov     cx,Y0
  4201.     mov     si,X0
  4202.     mov     di,si
  4203.     dec     si
  4204. @@triltloop:
  4205.     inc     cx
  4206.  
  4207.     add     ax,DP02
  4208.     jle     @@triltshortl
  4209.     sub     ax,DY02
  4210.     inc     si
  4211. @@triltshortl:
  4212.     add     si,XA02
  4213.     add     bx,DP01
  4214.     jle     @@triltshortr
  4215.     sub     bx,DY01
  4216.     inc     di
  4217. @@triltshortr:
  4218.     add     di,XA01
  4219.     push    si
  4220.     push    di
  4221.     cmp     cx,Y1
  4222.     jl      @@triltloop
  4223.     jmp     @@trilbstart
  4224. @@trilbloop:
  4225.     inc     cx
  4226.     add     ax,DP02
  4227.     jle     @@trilbshortl
  4228.     sub     ax,DY02
  4229.     inc     si
  4230. @@trilbshortl:
  4231.     add     si,XA02
  4232.  
  4233.     add     bx,DP12
  4234.     jle     @@trilbshortr
  4235.     sub     bx,DY12
  4236.     inc     di
  4237. @@trilbshortr:
  4238.     add     di,XA12
  4239.  
  4240.     push    si
  4241.     push    di
  4242. @@trilbstart:
  4243.     cmp     cx,Y2
  4244.     jl      @@trilbloop
  4245.     jmp     @@tridrawlines
  4246.  
  4247. @@tript1rt:
  4248.     mov     ax,0
  4249.     mov     bx,0
  4250.     mov     cx,Y0
  4251.     mov     si,X0
  4252.     mov     di,si
  4253.     dec     di
  4254. @@trirtloop:
  4255.     inc     cx
  4256.  
  4257.     add     ax,DP02
  4258.     jle     @@trirtshortl
  4259.     sub     ax,DY02
  4260.     inc     si
  4261. @@trirtshortl:
  4262.     add     si,XA02
  4263.  
  4264.     add     bx,DP01
  4265.     jle     @@trirtshortr
  4266.     sub     bx,DY01
  4267.     inc     di
  4268. @@trirtshortr:
  4269.     add     di,XA01
  4270.  
  4271.     push    di
  4272.     push    si
  4273.     cmp     cx,Y1
  4274.     jl      @@trirtloop
  4275.     jmp     @@trirbstart
  4276.  
  4277. @@trirbloop:
  4278.     inc     cx
  4279.     add     ax,DP02
  4280.     jle     @@trirbshortl
  4281.     sub     ax,DY02
  4282.     inc     si
  4283. @@trirbshortl:
  4284.     add     si,XA02
  4285.  
  4286.     add     bx,DP12
  4287.     jle     @@trirbshorts
  4288.     sub     bx,DY12
  4289.     inc     di
  4290. @@trirbshorts:
  4291.     add     di,XA12
  4292.  
  4293.     push    di
  4294.     push    si
  4295. @@trirbstart:
  4296.     cmp     cx,Y2
  4297.     jl      @@trirbloop
  4298.  
  4299. @@tridrawlines:
  4300.     mov     cx,SCREENSEG
  4301.     mov     es,cx
  4302.     mov     dx,SCINDEX
  4303.     mov     al,MAPMASK
  4304.     out     dx,al
  4305.  
  4306. @@lineloop:
  4307.     pop     ax
  4308.     pop     dx
  4309.     cmp     ax,dx
  4310.     jg      @@tridrawnext
  4311.     mov     bx,Color
  4312.     mov     cx,Y2
  4313.     add     dx,2
  4314.     mov     di,PageOffset
  4315.     call    HLineClipR
  4316. @@tridrawnext:
  4317.     dec     word ptr Y2
  4318.     dec     word ptr DY02
  4319.     jnz     @@lineloop
  4320.  
  4321. @@tridone:
  4322.     pop     ds
  4323.     pop       es
  4324.     pop       di
  4325. end;
  4326.  
  4327. Procedure XPolygon( var vertices; numvertices, Color, PageOffset:word ); assembler;
  4328. var
  4329.     x0, y0, tricount : integer;
  4330. asm
  4331.     mov   cx,numvertices
  4332.     cmp   cx,3
  4333.     jl    @@Done
  4334.     sub   cx,3
  4335.     mov   tricount,cx
  4336.     les   di,vertices
  4337.     mov   ax,es:[di]
  4338.     mov   x0,ax
  4339.     mov   ax,es:[di+2]
  4340.     mov   y0,ax
  4341.  
  4342. @@NextTriangle:
  4343.     add   di, 4
  4344.     mov        ax, x0
  4345.     push  ax
  4346.     mov   ax, y0
  4347.     push  ax
  4348.     mov   ax, es:[di+4]
  4349.     push  ax
  4350.     mov   ax, es:[di+6]
  4351.     push  ax
  4352.     mov   ax,es:[di]
  4353.     push    ax
  4354.     mov   ax,es:[di+2]
  4355.     push  ax
  4356.     mov     ax, color
  4357.     push  ax
  4358.     mov     ax, pageoffset
  4359.     push  ax
  4360.     call  xtriangle
  4361.     dec   tricount
  4362.     jns   @@NextTriangle
  4363. @@Done:
  4364.  
  4365. end;
  4366.  
  4367. Procedure XPutCursor( X, Y, TopClip, BottomClip, ScrnOffs : word ); assembler;
  4368. var
  4369.     Height,TopRow,NextLineIncr:word;
  4370. asm
  4371.     push  si
  4372.     push  di
  4373.     push  ds
  4374.     mov   ax,seg @data
  4375.     mov   ds,ax
  4376.     cld
  4377.     mov   ax,14
  4378.     mov   bx,Y
  4379.     mov   dx,TopClip
  4380.     sub   dx,bx
  4381.     jle   @@NotTopClip
  4382.     cmp   dx,ax
  4383.     jnl   @@NotVisible
  4384.     mov   cx,dx
  4385.     sub   ax,dx
  4386.     add   bx,dx
  4387.     jmp   @@VertClipDone
  4388.  
  4389. @@NotVisible:
  4390.     pop   ds
  4391.     pop   di
  4392.     pop   si
  4393.     jmp     @@Done
  4394.  
  4395. @@NotTopClip:
  4396.     mov   dx,BottomClip
  4397.     sub   dx,bx
  4398.     js    @@NotVisible
  4399.     mov   cx,0
  4400.     cmp   dx,ax
  4401.     jg    @@VertClipDone
  4402.     inc   dx
  4403.     mov   ax,dx
  4404.  
  4405. @@VertClipDone:
  4406.     mov   Height,ax
  4407.     mov   TopRow,cx
  4408.     mov   ax,SCREENSEG
  4409.     mov   es,ax
  4410.     mov   ax,bx
  4411.     mov   cx,ScrnLogicalByteWidth
  4412.     mul   cx
  4413.     mov   di,ax
  4414.     sub   cx,3
  4415.     mov   NextLineIncr,cx
  4416.     mov   cx,X
  4417.     mov   bx,cx
  4418.     shr   cx,2
  4419.     add   di,cx
  4420.     and   bx,3
  4421.     add   di,ScrnOffs
  4422.     mov   ax,42
  4423.     mul   bx
  4424.     mov   si,offset MouseMask
  4425.     add   si,ax
  4426.     mov   ax,3
  4427.     mul   TopRow
  4428.     add   si,ax
  4429.     mov   dx,SCINDEX
  4430.     mov   al,MAPMASK
  4431.     out   dx,al
  4432.     inc   dx
  4433.     mov   ah,byte ptr Height
  4434.     mov   bl,MouseColor
  4435.  
  4436. @@RowLoop:
  4437.     mov   cx,3
  4438.  
  4439. @@ColLoop:
  4440.     lodsb
  4441.     out   dx,al
  4442.     mov   es:[di],bl
  4443.     inc   di
  4444.     loop  @@ColLoop
  4445.  
  4446.     add   di,NextLineIncr
  4447.     dec   ah
  4448.     jnz   @@RowLoop
  4449.  
  4450.     pop   ds
  4451.     pop   di
  4452.     pop   si
  4453.  
  4454. @@Done:
  4455.  
  4456. end;
  4457.  
  4458. Procedure GetBG; near; assembler;
  4459. asm
  4460.     push  ds
  4461.     cld
  4462.     mov   cx,ScrnLogicalByteWidth
  4463.     mul   cx
  4464.     add   si,ax
  4465.     sub   cx,3
  4466.     shr   bx,2
  4467.     add   si,bx
  4468.     mov   bx,cx
  4469.     mov   di,BGSaveOffs
  4470.     mov   ax,SCREENSEG
  4471.     mov   es,ax
  4472.     mov   ds,ax
  4473.     mov   dx,GCINDEX
  4474.     mov   ax,BITMASK
  4475.     out   dx,ax
  4476.     mov   dx,SCINDEX
  4477.     mov   al,MAPMASK
  4478.     out   dx,al
  4479.     inc   dx
  4480.     mov   al,0fh
  4481.     out   dx,al
  4482.     mov   cx,14
  4483. @@Loop:
  4484.     movsb
  4485.     movsb
  4486.     movsb
  4487.     add si,bx
  4488.     loop @@Loop
  4489.     mov  dx,GCINDEX+1
  4490.     mov  al,0ffh
  4491.     out  dx,al
  4492.     pop  ds
  4493. end;
  4494.  
  4495. Procedure RestoreBG; near; assembler;
  4496. asm
  4497.     push  ds
  4498.     cld
  4499.     mov   cx,ScrnLogicalByteWidth
  4500.     mul   cx
  4501.     add   di,ax
  4502.     sub   cx,3
  4503.     shr   bx,2
  4504.     add   di,bx
  4505.     mov   si,BGSaveOffs
  4506.     mov   ax,SCREENSEG
  4507.     mov   es,ax
  4508.     mov   ds,ax
  4509.     mov   dx,GCINDEX
  4510.     mov   ax,BITMASK
  4511.     out   dx,ax
  4512.     mov   dx,SCINDEX
  4513.     mov   al,MAPMASK
  4514.     out   dx,al
  4515.     inc   dx
  4516.     mov   al,0fh
  4517.     out   dx,al
  4518.     mov   bx,cx
  4519.     mov   cx,14
  4520. @@Loop:
  4521.     movsb
  4522.     movsb
  4523.     movsb
  4524.     add di,bx
  4525.     loop @@Loop
  4526.     mov  dx,GCINDEX+1
  4527.     mov  al,0ffh
  4528.     out  dx,al
  4529.     pop   ds
  4530. end;
  4531.  
  4532. Procedure UpdateCursor; near; assembler;
  4533. asm
  4534.     mov dx,InputStatus0
  4535. @@WaitNotVsync:
  4536.     in  al,dx
  4537.     test al,08h
  4538.     jnz @@WaitNotVSync
  4539. @@WaitVSync:
  4540.     in  al,dx
  4541.     test al,08h
  4542.     jz  @@WaitVSync
  4543.     mov di,OldScrnOffs
  4544.     mov ax,OldY
  4545.     mov bx,OldX
  4546.     call restorebg
  4547.     mov si,VisiblePageOffs
  4548.     mov ax,MouseY
  4549.     mov bx,MouseX
  4550.     mov OldScrnOffs,si
  4551.     mov OldY,ax
  4552.     mov OldX,bx
  4553.     call getbg
  4554.     push OldX
  4555.     push OldY
  4556.     mov  ax,0
  4557.     push ax
  4558.     mov  ax,ScrnPhysicalHeight
  4559.     push ax
  4560.     push VisiblePageOffs
  4561.     call xputcursor
  4562. end;
  4563.  
  4564. Procedure MouseHandler; far; assembler;
  4565. asm
  4566.     push  ds
  4567.     mov   di,seg @data
  4568.     mov   ds,di
  4569.     cmp   inhandler,1
  4570.     jne   @@NotActive
  4571.     jmp     @@Done2
  4572. @@NotActive:
  4573.     mov   inhandler,1
  4574.     mov   MouseButtonStatus,bx
  4575.     test  ax,1
  4576.     jz    @@Done
  4577.     shr   cx,1
  4578.     mov   MouseX,cx
  4579.     mov   MouseY,dx
  4580.     cmp   MouseHidden,1
  4581.     je    @@Done
  4582.     cmp   MouseFrozen,1
  4583.     je    @@Done
  4584.     call  updatecursor
  4585.  
  4586. @@Done:
  4587.     mov  inhandler,0
  4588. @@Done2:
  4589.     pop  ds
  4590. end;
  4591.  
  4592. Procedure XDefineMouseCursor( var MouseDef; MouseColor:byte ); assembler;
  4593. asm
  4594.     cmp   MouseInstalled,0
  4595.     je    @@Done
  4596.     mov   al,MouseColor
  4597.     mov   MouseColor,al
  4598.     push  si
  4599.     push  di
  4600.     push  ds
  4601.     mov   ax,ds
  4602.     mov   es,ax
  4603.     mov   di,offset MouseMask
  4604.     lds   si,MouseDef
  4605.     xor   cl,cl
  4606. @@AlignmentLoop:
  4607.     push  si
  4608.     mov   dh,14
  4609. @@RowLoop:
  4610.     lodsb
  4611.     xor   ah,ah
  4612.     shl   ax,cl
  4613.     mov   bl,al
  4614.     and   bl,0fh
  4615.     mov   es:[di],bl
  4616.     inc   di
  4617.     shr   al,4
  4618.     stosw
  4619.     dec   dh
  4620.     jnz   @@RowLoop
  4621.     pop   si
  4622.     inc   cl
  4623.     cmp   cl,4
  4624.     jne   @@AlignmentLoop
  4625.     pop   ds
  4626.     pop   di
  4627.     pop   si
  4628. @@Done:
  4629. end;
  4630.  
  4631.  
  4632. procedure XMouseInit; assembler;
  4633. asm
  4634.     mov   InHandler,0
  4635.     mov     mousehidden,0
  4636.     mov     BGSaveOffs,0
  4637.     mov     MouseX,0
  4638.     mov     MOuseY,0
  4639.     mov        MouseButtonStatus,0
  4640.     mov        MouseFrozen,0
  4641.     mov     MouseColor,0
  4642.     mov     MouseInstalled,0
  4643.     cmp   MouseButtonCount,0
  4644.     jne   @@DontInitialize
  4645.     xor   ax,ax
  4646.     int   33h
  4647.     or    ax,ax
  4648.     jz    @@Done
  4649.     mov   MouseButtonCount,bx
  4650.  
  4651. @@DontInitialize:
  4652.     mov   MouseInstalled,ax
  4653.     or    ax,ax
  4654.     jz    @@Done
  4655.     mov   ax,NonVisualOffs
  4656.     mov   BGSaveOffs,ax
  4657.     add   ax,42
  4658.     mov   NonVisualOffs,ax
  4659.     mov   ax,02
  4660.     int   33h
  4661.     mov   MouseInstalled,1
  4662.     mov   ax,07h
  4663.     mov   cx,0
  4664.     mov   dx,ScrnPhysicalPixelWidth
  4665.     shl   dx,1
  4666.     int   33h
  4667.     mov   ax,08h
  4668.     mov   cx,0
  4669.     mov   dx,ScrnPhysicalHeight
  4670.     int   33h
  4671.     mov   ax,0fh
  4672.     mov   cx,4
  4673.     mov   dx,8
  4674.     int   33h
  4675.     mov   ax,3
  4676.     int   33h
  4677.     mov   MouseY,dx
  4678.     shr   cx,1
  4679.     mov   MouseX,cx
  4680.     mov   ax,12
  4681.     mov   bx,seg mousehandler
  4682.     mov   es,bx
  4683.     mov   dx,offset mousehandler
  4684.     mov   cx,1fh
  4685.     int   33h
  4686.     mov   MouseHidden,1
  4687.     push  ds
  4688.     mov   ax,offset InitMouseDef
  4689.     push  ax
  4690.     mov   al, MouseColor
  4691.     push  ax
  4692.     call  xdefinemousecursor
  4693.     mov   ax,MouseInstalled
  4694. @@Done:
  4695. end;
  4696.  
  4697. Procedure XMouseWindow( x0, y0, x1, y1:word ); assembler;
  4698. asm
  4699.     mov   ax,7
  4700.     mov   cx,x0
  4701.     shl   cx,1
  4702.     mov   dx,x1
  4703.     shl   dx,1
  4704.     int   33h
  4705.     mov   ax,8
  4706.     mov   cx,y0
  4707.     mov   dx,y1
  4708.     int   33h
  4709. end;
  4710.  
  4711.  
  4712. procedure XShowMouse; assembler;
  4713. asm
  4714.     cmp   MouseInstalled,0
  4715.     je    @@Done
  4716.     cmp   MouseHidden,0
  4717.     je    @@Done
  4718.     push  si
  4719.     push  di
  4720.  
  4721. @@WaitEndOfHandler:
  4722.     mov   cl,inhandler
  4723.     or    cl,cl
  4724.     jnz   @@WaitEndOfHandler
  4725.     mov   si,VisiblePageOffs
  4726.     mov   ax,MouseY
  4727.     mov   bx,MouseX
  4728.     mov   OldScrnOffs,si
  4729.     mov   OldY,ax
  4730.     mov   OldX,bx
  4731.     call  getbg
  4732.     push  OldX
  4733.     push  OldY
  4734.     xor   ax,ax
  4735.     push  ax
  4736.     push  ScrnLogicalHeight
  4737.     push  VisiblePageOffs
  4738.     call  xputcursor
  4739.     mov   MouseHidden,0
  4740.     pop   di
  4741.     pop   si
  4742. @@Done:
  4743. end;
  4744.  
  4745. Procedure XHideMouse; assembler;
  4746. asm
  4747.     cmp   MouseInstalled,0
  4748.     je    @@Done
  4749.     cmp   MouseHidden,0
  4750.     jne   @@Done
  4751.     push  si
  4752.     push  di
  4753. @@WaitEndOfHandler:
  4754.     mov   cl,inhandler
  4755.     or    cl,cl
  4756.     jnz   @@WaitEndOfHandler
  4757.     mov   MouseHidden,TRUE
  4758.     mov   di,OldScrnOffs
  4759.     mov   ax,OldY
  4760.     mov   bx,OldX
  4761.     call  restorebg
  4762.     pop   di
  4763.     pop   si
  4764. @@Done:
  4765. end;
  4766.  
  4767. Procedure XMouseRemove; assembler;
  4768. asm
  4769.     cmp   MouseInstalled,0
  4770.     je    @@Done
  4771.     call  xhidemouse
  4772.     mov   ax,12
  4773.     xor   cx,cx
  4774.     int   33h
  4775.     mov   MouseInstalled,0
  4776. @@Done:
  4777. end;
  4778.  
  4779. Procedure XPositionMouse( X, Y : word ); assembler;
  4780. asm
  4781. @@WaitEndOfHandler:
  4782.     mov   bl,inhandler
  4783.     or    bl,bl
  4784.     jnz   @@WaitEndOfHandler
  4785.     mov   ax,4
  4786.     mov   cx,X
  4787.     mov   dx,Y
  4788.     mov   MouseX,cx
  4789.     mov   MouseY,dx
  4790.     shl   cx,1
  4791.     mov   inhandler,1
  4792.     int   33h
  4793.     cmp   MouseHidden,FALSE
  4794.     jne   @@NotVisible
  4795.     push  di
  4796.     push  si
  4797.     call  updatecursor
  4798.     pop   si
  4799.     pop   di
  4800. @@NotVisible:
  4801.     mov   inhandler,0
  4802. end;
  4803.  
  4804. Procedure XUpdateMouse; assembler;
  4805. asm
  4806.     cmp   MouseInstalled,0
  4807.     je    @@Done
  4808.     cmp   MouseHidden,0
  4809.     jne   @@Done
  4810.     push  si
  4811.     push  di
  4812.     mov   ax,03h
  4813.     int   33h
  4814.     shr   cx,1
  4815.     mov   MouseX,cx
  4816.     mov   MouseY,dx
  4817.     mov   MouseButtonStatus,bx
  4818.     call  updatecursor
  4819.     pop   di
  4820.     pop   si
  4821. @@Done:
  4822. end;
  4823.  
  4824. Procedure XPutMaskedPBMClipX( X, Y, ScrnOffs:word; var Bitmap ); assembler;
  4825. var
  4826.     Plane:byte;
  4827.     CType,LeftSkip,DataInc,Width,Height,TopRow,LineInc:word;
  4828. asm
  4829.     push  ds
  4830.     cld
  4831.     les   si,Bitmap
  4832.     xor   ax,ax
  4833.     mov   CType,ax
  4834.     mov   al,byte ptr es:[si]
  4835.     mov   di,X
  4836.     mov   cx,di
  4837.     sar   di,2
  4838.     mov   dx,LeftClip
  4839.     sub   dx,di
  4840.     jle   @@NotLeftClip
  4841.     cmp   dx,ax
  4842.     jnl   @@NotVisible
  4843.     add   di,dx
  4844.     mov   LeftSkip,dx
  4845.     mov   DataInc,dx
  4846.     sub   ax,dx
  4847.     mov   CType,1
  4848.     jmp   @@HorizClipDone
  4849.  
  4850. @@NotVisible:
  4851.     mov   ax,1
  4852.     jmp @@Bye
  4853.  
  4854. @@NotLeftClip:
  4855.     mov   dx,RightClip
  4856.     sub   dx,di
  4857.     js    @@NotVisible
  4858.     mov   LeftSkip,0
  4859.     mov   DataInc,0
  4860.     cmp   dx,ax
  4861.     jge   @@HorizClipDone
  4862.     inc   dx
  4863.     sub   ax,dx
  4864.     mov   DataInc,ax
  4865.     mov   ax,dx
  4866.     mov   CType,-1
  4867. @@HorizClipDone:
  4868.     xor   bh,bh
  4869.     mov   bl,byte ptr es:[si+1]
  4870.     mov   Width,ax
  4871.     mov   Height,bx
  4872.     add   si,2
  4873.     add   si,LeftSkip
  4874.     mov   bx,ScrnLogicalByteWidth
  4875.     mov   dx,bx
  4876.     sub   dx,ax
  4877.     mov   LineInc,dx
  4878.     mov   ax,Y
  4879.     mul   bx
  4880.     add   di,ax
  4881.     add   di,ScrnOffs
  4882.     mov   ax,es
  4883.     mov   ds,ax
  4884.     mov   ax,SCREENSEG
  4885.     mov   es,ax
  4886.     and   cx,3
  4887.     mov   ah,11h
  4888.     shl   ah,cl
  4889.     mov   dx,SCINDEX
  4890.     mov   al,MAPMASK
  4891.     out   dx,al
  4892.     inc   dx
  4893.     mov   Plane,4
  4894.     mov   bh,byte ptr Width
  4895. @@PlaneLoop:
  4896.     push  di
  4897.     mov   bl,byte ptr Height
  4898.     mov   al,ah
  4899.     out   dx,al
  4900. @@RowLoop:
  4901.     mov   cl,bh
  4902.     jcxz  @@NoWidth
  4903. @@ColLoop:
  4904.     lodsb
  4905.     or    al,al
  4906.     jz    @@NoPixel
  4907.     mov   es:[di],al
  4908. @@NoPixel:
  4909.     inc   di
  4910.     loop @@ColLoop
  4911. @@NoWidth:
  4912.     add   si,DataInc
  4913.     add   di,LineInc
  4914.     dec   bl
  4915.     jnz   @@RowLoop
  4916.     pop   di
  4917.     rol   ah,1
  4918.     jnb   @@Nocarry
  4919.     mov   bl,ah
  4920.     mov   ax,CType
  4921.     add   bh,al
  4922.     sub   DataInc,ax
  4923.     sub   LineInc,ax
  4924.     cmp   al,0
  4925.     mov   ah,bl
  4926.     jg    @@RightAdvance
  4927.     inc   di
  4928.     jmp   @@Nocarry
  4929. @@RightAdvance:
  4930.     dec si
  4931. @@Nocarry:
  4932.     dec   Plane
  4933.     jnz   @@PlaneLoop
  4934.     xor   ax,ax
  4935. @@Bye:
  4936.     pop   ds
  4937.  
  4938. end;
  4939.  
  4940. procedure XPutMaskedPBMClipY( X, Y, ScrnOffs:word; var Bitmap ); assembler;
  4941. var
  4942.     Width,Height,TopRow,LineInc,PlaneInc:word;
  4943. asm
  4944.     push  ds
  4945.     cld
  4946.     les   si,Bitmap
  4947.     xor   bh,bh
  4948.     mov   bl,byte ptr es:[si+1]
  4949.     xor   ah,ah
  4950.     mov   al,byte ptr es:[si]
  4951.     mov   cx,ax
  4952.     mul   bx
  4953.     mov   PlaneInc,ax
  4954.     mov   ax,cx
  4955.     mov   di,X
  4956.     mov   cx,di
  4957.     shr   di,2
  4958.     mov   dx,TopClip
  4959.     sub   dx,Y
  4960.     jle   @@NotTopClip
  4961.     cmp   dx,bx
  4962.     jnl   @@NotVisible
  4963.     mov   TopRow,dx
  4964.     sub   bx,dx
  4965.     add   Y,dx
  4966.     jmp   @@VertClipDone
  4967.  
  4968. @@NotVisible:
  4969.     mov   ax,1
  4970.     pop   ds
  4971.     pop   di
  4972.     pop   si
  4973.     mov   sp,bp
  4974.     pop   bp
  4975.     ret
  4976.  
  4977. @@NotTopClip:
  4978.     mov   dx,BottomClip
  4979.     sub   dx,Y
  4980.     js    @@NotVisible
  4981.     mov   TopRow,0
  4982.     cmp   dx,bx
  4983.     jg    @@VertClipDone
  4984.     inc   dx
  4985.     mov   bx,dx
  4986.  
  4987. @@VertClipDone:
  4988.  
  4989.     mov   Width,ax
  4990.     mov   Height,bx
  4991.     mul   TopRow
  4992.     add   ax,2
  4993.     add   si,ax
  4994.  
  4995.  
  4996.     mov   ax,Y
  4997.     mov   bx,ScrnLogicalByteWidth
  4998.     mul   bx
  4999.     add   di,ax
  5000.     add   di,ScrnOffs
  5001.     sub   bx,Width
  5002.     mov   LineInc,bx
  5003.     mov   ax,es
  5004.     mov   ds,ax
  5005.     mov   ax,SCREENSEG
  5006.     mov   es,ax
  5007.  
  5008.     mov   ah,11h
  5009.     and   cx,3
  5010.     shl   ah,cl
  5011.  
  5012.     mov   dx,SCINDEX
  5013.     mov   al,MAPMASK
  5014.     out   dx,al
  5015.     inc   dx
  5016.     mov   bh,4
  5017. @@PlaneLoop:
  5018.     push  di
  5019.     push  si
  5020.     mov   bl,byte ptr Height
  5021.     mov   al,ah
  5022.     out   dx,al
  5023. @@RowLoop:
  5024.     mov   cl,byte ptr Width
  5025. @@ColLoop:
  5026.     lodsb
  5027.     or    al,al
  5028.     jz    @@NoPixel
  5029.     mov   es:[di],al
  5030. @@NoPixel:
  5031.     inc   di
  5032.     loop  @@ColLoop
  5033.     add   di,LineInc
  5034.     dec   bl
  5035.     jnz   @@RowLoop
  5036.     pop   si
  5037.     add   si,PlaneInc
  5038.     pop   di
  5039.     rol   ah,1
  5040.     adc   di,0
  5041.     dec   bh
  5042.     jnz   @@PlaneLoop
  5043.     xor   ax,ax
  5044.     pop   ds
  5045. end;
  5046.  
  5047. Procedure XPutMaskedPBMClipXY( X, Y, ScrnOffs:word; var Bitmap ); assembler;
  5048. var
  5049.     Plane:byte;
  5050.     CType,LeftSkip,DataInc,Width,Height,TopRow,LineInc,PlaneInc:word;
  5051. asm
  5052.     push  ds
  5053.     cld
  5054.     les   si,Bitmap
  5055.     xor   ax,ax
  5056.     mov   CType,ax
  5057.     mov   al,byte ptr es:[si]
  5058.     xor   bh,bh
  5059.     mov   bl,byte ptr es:[si+1]
  5060.     mov   cx,ax
  5061.     mul   bx
  5062.     mov   PlaneInc,ax
  5063.     mov   ax,cx
  5064.     mov   di,X
  5065.     mov   cx,di
  5066.     sar   di,2
  5067.     mov   dx,TopClip
  5068.     sub   dx,Y
  5069.     jle   @@NotTopClip
  5070.     cmp   dx,bx
  5071.     jnl   @@NotVisible
  5072.     mov   TopRow,dx
  5073.     sub   bx,dx
  5074.     add   Y,dx
  5075.     jmp   @@VertClipDone
  5076.  
  5077. @@NotVisible:
  5078.     mov   ax,1
  5079.     jmp @@Bye
  5080.  
  5081. @@NotTopClip:
  5082.     mov   dx,BottomClip
  5083.     sub   dx,Y
  5084.     js    @@NotVisible
  5085.     mov   TopRow,0
  5086.     cmp   dx,bx
  5087.     jg    @@VertClipDone
  5088.     inc   dx
  5089.     mov   bx,dx
  5090.  
  5091. @@VertClipDone:
  5092.     mov   dx,LeftClip
  5093.     sub   dx,di
  5094.     jle   @@NotLeftClip
  5095.     cmp   dx,ax
  5096.     jnl   @@NotVisible
  5097.     add   di,dx
  5098.     mov   LeftSkip,dx
  5099.     mov   DataInc,dx
  5100.     sub   ax,dx
  5101.     mov   CType,1
  5102.     jmp   @@HorizClipDone
  5103.  
  5104. @@NotLeftClip:
  5105.     mov   dx,RightClip
  5106.     sub   dx,di
  5107.     js    @@NotVisible
  5108.     mov   LeftSkip,0
  5109.     mov   DataInc,0
  5110.     cmp   dx,ax
  5111.     jge   @@HorizClipDone
  5112.     inc   dx
  5113.     sub   ax,dx
  5114.     mov   DataInc,ax
  5115.     mov   ax,dx
  5116.     mov   CType,-1
  5117.  
  5118. @@HorizClipDone:
  5119.     mov   Width,ax
  5120.     mov   Height,bx
  5121.     add   ax,DataInc
  5122.     mul   TopRow
  5123.     add   si,ax
  5124.     add   si,2
  5125.     add   si,LeftSkip
  5126.     mov   bx,ScrnLogicalByteWidth
  5127.     mov   dx,bx
  5128.     sub   dx,Width
  5129.     mov   LineInc,dx
  5130.     mov   ax,Y
  5131.     mul   bx
  5132.     add   di,ax
  5133.     add   di,ScrnOffs
  5134.     mov   ax,es
  5135.     mov   ds,ax
  5136.     mov   ax,SCREENSEG
  5137.     mov   es,ax
  5138.     and   cx,3
  5139.     mov   ah,11h
  5140.     shl   ah,cl
  5141.     mov   dx,SCINDEX
  5142.     mov   al,MAPMASK
  5143.     out   dx,al
  5144.     inc   dx
  5145.     mov   Plane,4
  5146.     mov   bh,byte ptr Width
  5147. @@PlaneLoop:
  5148.     push  di
  5149.     push  si
  5150.     mov   bl,byte ptr Height
  5151.     mov   al,ah
  5152.     out   dx,al
  5153. @@RowLoop:
  5154.     mov   cl,bh
  5155.     jcxz   @@NoWidth
  5156. @@ColLoop:
  5157.     lodsb
  5158.     or    al,al
  5159.     jz    @@NoPixel
  5160.     mov   es:[di],al
  5161. @@NoPixel:
  5162.     inc   di
  5163.     loop @@ColLoop
  5164. @@NoWidth:
  5165.     add   si,DataInc
  5166.     add   di,LineInc
  5167.     dec   bl
  5168.     jnz   @@RowLoop
  5169.     pop   si
  5170.     add   si,PlaneInc
  5171.     pop   di
  5172.     rol   ah,1
  5173.     jnb   @@Nocarry
  5174.     mov   bl,ah
  5175.     mov   ax,CType
  5176.     add   bh,al
  5177.     sub   DataInc,ax
  5178.     sub   LineInc,ax
  5179.     cmp   al,0
  5180.     mov   ah,bl
  5181.     jg    @@RightAdvance
  5182.     inc   di
  5183.     jmp   @@Nocarry
  5184. @@RightAdvance:
  5185.     dec   si
  5186. @@Nocarry:
  5187.     dec   Plane
  5188.     jnz   @@PlaneLoop
  5189.  
  5190.     xor   ax,ax
  5191. @@Bye:
  5192.     pop   ds
  5193. end;
  5194.  
  5195. Procedure XPutPBMClipX( X, Y, ScrnOffs:word; var Bitmap ); assembler;
  5196. var
  5197.     Plane:byte;
  5198.     CType,LeftSkip,DataInc,Width,Height,TopRow,LineInc:word;
  5199. asm
  5200.     push  ds
  5201.     cld
  5202.     les   si,Bitmap
  5203.     xor   ax,ax
  5204.     mov   CType,ax
  5205.     mov   al,byte ptr es:[si]
  5206.     mov   di,X
  5207.     mov   cx,di
  5208.     sar   di,2
  5209.     mov   dx,LeftClip
  5210.     sub   dx,di
  5211.     jle   @@NotLeftClip
  5212.     cmp   dx,ax
  5213.     jnl   @@NotVisible
  5214.     add   di,dx
  5215.     mov   LeftSkip,dx
  5216.     mov   DataInc,dx
  5217.     sub   ax,dx
  5218.     mov   CType,1
  5219.     jmp   @@HorizClipDone
  5220.  
  5221. @@NotVisible:
  5222.     mov   ax,1
  5223.     jmp @@Bye
  5224.  
  5225. @@NotLeftClip:
  5226.     mov   dx,RightClip
  5227.     sub   dx,di
  5228.     js    @@NotVisible
  5229.     mov   LeftSkip,0
  5230.     mov   DataInc,0
  5231.     cmp   dx,ax
  5232.     jge   @@HorizClipDone
  5233.     inc   dx
  5234.     sub   ax,dx
  5235.     mov   DataInc,ax
  5236.     mov   ax,dx
  5237.     mov   CType,-1
  5238.  
  5239. @@HorizClipDone:
  5240.     xor   bh,bh
  5241.     mov   bl,byte ptr es:[si+1]
  5242.     mov   Width,ax
  5243.     mov   Height,bx
  5244.     add   si,2
  5245.     add   si,LeftSkip
  5246.     mov   bx,ScrnLogicalByteWidth
  5247.     mov   dx,bx
  5248.     sub   dx,ax
  5249.     mov   LineInc,dx
  5250.     mov   ax,Y
  5251.     mul   bx
  5252.     add   di,ax
  5253.     add   di,ScrnOffs
  5254.     mov   ax,es
  5255.     mov   ds,ax
  5256.     mov   ax,SCREENSEG
  5257.     mov   es,ax
  5258.     and   cx,3
  5259.     mov   ah,11h
  5260.     shl   ah,cl
  5261.     mov   dx,SCINDEX
  5262.     mov   al,MAPMASK
  5263.     out   dx,al
  5264.     inc   dx
  5265.     mov   Plane,4
  5266.     mov   bh,byte ptr Width
  5267. @@PlaneLoop:
  5268.     push  di
  5269.     mov   bl,byte ptr Height
  5270.     mov   al,ah
  5271.     out   dx,al
  5272. @@RowLoop:
  5273.     mov   cl,bh
  5274.     shr   cl,1
  5275.     rep   movsw
  5276.     adc   cl,0
  5277.     rep   movsb
  5278.     add   si,DataInc
  5279.     add   di,LineInc
  5280.     dec   bl
  5281.     jnz   @@RowLoop
  5282.     pop   di
  5283.     rol   ah,1
  5284.     jnb   @@Nocarry
  5285.     mov   bl,ah
  5286.     mov   ax,CType
  5287.     add   bh,al
  5288.     sub   DataInc,ax
  5289.     sub   LineInc,ax
  5290.     cmp   al,0
  5291.     mov   ah,bl
  5292.     jg    @@RightAdvance
  5293.     inc   di
  5294.     jmp   @@Nocarry
  5295. @@RightAdvance:
  5296.     dec si
  5297. @@Nocarry:
  5298.     dec   Plane
  5299.     jnz   @@PlaneLoop
  5300.     xor   ax,ax
  5301. @@Bye:
  5302.     pop   ds
  5303. end;
  5304.  
  5305.  
  5306. Procedure XPutPBMClipY( X, Y, ScrnOffs : word; var Bitmap ); assembler;
  5307. var
  5308.     Width,Height,TopRow,LineInc,PlaneInc:word;
  5309. asm
  5310.     push  ds
  5311.     cld
  5312.     les   si,Bitmap
  5313.     xor   bh,bh
  5314.     mov   bl,byte ptr es:[si+1]
  5315.     xor   ah,ah
  5316.     mov   al,byte ptr es:[si]
  5317.     mov   [Width],ax
  5318.  
  5319.     mov   cx,ax
  5320.     mul   bx
  5321.     mov   PlaneInc,ax
  5322.     mov   ax,cx
  5323.  
  5324.     mov   di,X
  5325.     mov   cx,di
  5326.     and   cx,3
  5327.     shr   di,2
  5328.     mov   dx,TopClip
  5329.     sub   dx,Y
  5330.     jle   @@NotTopClip
  5331.     cmp   dx,bx
  5332.     jnl   @@NotVisible
  5333.     mov   TopRow,dx
  5334.     sub   bx,dx
  5335.     add   Y,dx
  5336.     jmp   @@VertClipDone
  5337.  
  5338. @@NotVisible:
  5339.     mov   ax,1
  5340.     jmp @@Bye
  5341.  
  5342. @@NotTopClip:
  5343.     mov   dx,BottomClip
  5344.     sub   dx,Y
  5345.     js    @@NotVisible
  5346.     mov   TopRow,0
  5347.     cmp   dx,bx
  5348.     jg    @@VertClipDone
  5349.     inc   dx
  5350.     mov   bx,dx
  5351.  
  5352. @@VertClipDone:
  5353.  
  5354.     mov   Height,bx
  5355.     mul   TopRow
  5356.     add   ax,2
  5357.     add   si,ax
  5358.     mov   ax,Y
  5359.     mov   bx,ScrnLogicalByteWidth
  5360.     mul   bx
  5361.     add   di,ax
  5362.     add   di,ScrnOffs
  5363.     sub   bx,Width
  5364.     mov   LineInc,bx
  5365.     mov   ax,es
  5366.     mov   ds,ax
  5367.     mov   ax,SCREENSEG
  5368.     mov   es,ax
  5369.     mov   ah,11h
  5370.     shl   ah,cl
  5371.     mov   dx,SCINDEX
  5372.     mov   al,MAPMASK
  5373.     out   dx,al
  5374.     inc   dx
  5375.     mov   bh,4
  5376. @@PlaneLoop:
  5377.     push  di
  5378.     push  si
  5379.     mov   bl,byte ptr Height
  5380.     mov   al,ah
  5381.     out   dx,al
  5382. @@RowLoop:
  5383.     mov   cl,byte ptr Width
  5384.     shr   cl,1
  5385.     rep   movsw
  5386.     adc   cl,0
  5387.     rep   movsb
  5388.     add   di,LineInc
  5389.     dec   bl
  5390.     jnz   @@RowLoop
  5391.     pop   si
  5392.     add   si,PlaneInc
  5393.     pop   di
  5394.     rol   ah,1
  5395.     adc   di,0
  5396.     dec   bh
  5397.     jnz   @@PlaneLoop
  5398.     xor   ax,ax
  5399. @@Bye:
  5400.     pop   ds
  5401. end;
  5402.  
  5403. Procedure XPutPBMClipXY( X, Y, ScrnOffs:word; var Bitmap ); assembler;
  5404. var
  5405.     Plane:byte;
  5406.     CType,LeftSkip,DataInc,Width,Height,TopRow,LineInc,PlaneInc:word;
  5407. asm
  5408.     push  ds
  5409.     cld
  5410.     les   si,Bitmap
  5411.     xor   ax,ax
  5412.     mov   CType,ax
  5413.     mov   al,byte ptr es:[si]
  5414.     xor   bh,bh
  5415.     mov   bl,byte ptr es:[si+1]
  5416.     mov   cx,ax
  5417.     mul   bx
  5418.     mov   PlaneInc,ax
  5419.     mov   ax,cx
  5420.     mov   di,X
  5421.     mov   cx,di
  5422.     sar   di,2
  5423.     mov   dx,TopClip
  5424.     sub   dx,Y
  5425.     jle   @@NotTopClip
  5426.     cmp   dx,bx
  5427.     jnl   @@NotVisible
  5428.     mov   TopRow,dx
  5429.     sub   bx,dx
  5430.     add   Y,dx
  5431.     jmp   @@VertClipDone
  5432.  
  5433. @@NotVisible:
  5434.     mov   ax,1
  5435.     jmp @@Bye
  5436.  
  5437. @@NotTopClip:
  5438.     mov   dx,BottomClip
  5439.     sub   dx,Y
  5440.     js    @@NotVisible
  5441.     mov   TopRow,0
  5442.     cmp   dx,bx
  5443.     jg    @@VertClipDone
  5444.     inc   dx
  5445.     mov   bx,dx
  5446.  
  5447. @@VertClipDone:
  5448.     mov   dx,LeftClip
  5449.     sub   dx,di
  5450.     jle   @@NotLeftClip
  5451.     cmp   dx,ax
  5452.     jnl   @@NotVisible
  5453.     add   di,dx
  5454.     mov   LeftSkip,dx
  5455.     mov   DataInc,dx
  5456.     sub   ax,dx
  5457.     mov   CType,1
  5458.     jmp   @@HorizClipDone
  5459.  
  5460. @@NotLeftClip:
  5461.     mov   dx,RightClip
  5462.     sub   dx,di
  5463.     js    @@NotVisible
  5464.     mov   LeftSkip,0
  5465.     mov   DataInc,0
  5466.     cmp   dx,ax
  5467.     jge   @@HorizClipDone
  5468.     inc   dx
  5469.     sub   ax,dx
  5470.     mov   DataInc,ax
  5471.     mov   ax,dx
  5472.     mov   CType,-1
  5473.  
  5474. @@HorizClipDone:
  5475.     mov   Width,ax
  5476.     mov   Height,bx
  5477.     add   ax,DataInc
  5478.     mul   TopRow
  5479.     add   si,ax
  5480.     add   si,2
  5481.     add   si,LeftSkip
  5482.     mov   bx,ScrnLogicalByteWidth
  5483.     mov   dx,bx
  5484.     sub   dx,Width
  5485.     mov   LineInc,dx
  5486.     mov   ax,Y
  5487.     mul   bx
  5488.     add   di,ax
  5489.     add   di,ScrnOffs
  5490.     mov   ax,es
  5491.     mov   ds,ax
  5492.     mov   ax,SCREENSEG
  5493.     mov   es,ax
  5494.     and   cx,3
  5495.     mov   ah,11h
  5496.     shl   ah,cl
  5497.     mov   dx,SCINDEX
  5498.     mov   al,MAPMASK
  5499.     out   dx,al
  5500.     inc   dx
  5501.     mov   Plane,4
  5502.     mov   bh,byte ptr Width
  5503. @@PlaneLoop:
  5504.     push  di
  5505.     push  si
  5506.     mov   bl,byte ptr Height
  5507.     mov   al,ah
  5508.     out   dx,al
  5509. @@RowLoop:
  5510.     mov   cl,bh
  5511.     shr   cl,1
  5512.     rep   movsw
  5513.     adc   cl,0
  5514.     rep   movsb
  5515.     add   si,DataInc
  5516.     add   di,LineInc
  5517.     dec   bl
  5518.     jnz   @@RowLoop
  5519.     pop   si
  5520.     add   si,PlaneInc
  5521.     pop   di
  5522.     rol   ah,1
  5523.     jnb   @@Nocarry
  5524.     mov   bl,ah
  5525.     mov   ax,CType
  5526.     add   bh,al
  5527.     sub   DataInc,ax
  5528.     sub   LineInc,ax
  5529.     cmp   al,0
  5530.     mov   ah,bl
  5531.     jg    @@RightAdvance
  5532.     inc   di
  5533.     jmp   @@Nocarry
  5534.  
  5535. @@RightAdvance:
  5536.     dec si
  5537.  
  5538. @@Nocarry:
  5539.     dec   Plane
  5540.     jnz   @@PlaneLoop
  5541.     xor   ax,ax
  5542. @@Bye:
  5543.     pop   ds
  5544. end;
  5545.  
  5546. Procedure XStoreVBMImage( VramOffs,Align:word; var LBitmap ); assembler;
  5547. var
  5548.     BMWidth:byte;
  5549. asm
  5550.     push  si
  5551.     push  di
  5552.     push  ds
  5553.     cld
  5554.     mov   ax,SCREENSEG
  5555.     mov   es,ax
  5556.     mov   di,VramOffs
  5557.     mov   bx,Align
  5558.     and   bl,03h
  5559.     lds   si,LBitmap
  5560.     lodsw
  5561.     mov   bh,ah
  5562.     mov   BMWidth,al
  5563.     mov   dx,SCINDEX
  5564.     mov   al,MAPMASK
  5565.     out   dx,al
  5566.     inc   dx
  5567.     xor   ch,ch
  5568. @@RowLoop:
  5569.     mov   cl,bl
  5570.     mov   ah,11h
  5571.     shl   ah,cl
  5572.     mov   cl,BMWidth
  5573. @@ColLoop:
  5574.     mov   al,ah
  5575.     out   dx,al
  5576.     lodsb
  5577.     mov   es:[di],al
  5578.     shl   ah,1
  5579.     jnb   @@NoAddrIncr
  5580.     inc   di
  5581.     mov   ah,11h
  5582. @@NoAddrIncr:
  5583.     loop  @@ColLoop
  5584.     cmp   ah,11h
  5585.     inc   di
  5586.     dec   bh
  5587.     jnz   @@RowLoop
  5588.     mov   ax,di
  5589.     sub   ax,VramOffs
  5590.     pop   ds
  5591.     pop   di
  5592.     pop   si
  5593. end;
  5594.  
  5595. Procedure XPutMaskedVBM( X, Y, ScrnOffs:word; var SrcVBM ); assembler;
  5596. var
  5597.     VBMWidth, VBMHeight, NextLineIncr:word;
  5598. asm
  5599.     push  si
  5600.     push  di
  5601.     push  ds
  5602.     cld
  5603.     mov   ax,SCREENSEG
  5604.     mov   es,ax
  5605.     mov   ax,Y
  5606.     mov   cx,ScrnLogicalByteWidth
  5607.     mul   cx
  5608.     mov   di,ScrnOffs
  5609.     add   di,ax
  5610.     mov   si,X
  5611.     mov   bx,si
  5612.     shr   bx,2
  5613.     add   di,bx
  5614.     and   si,3
  5615.     lds   bx,SrcVBM
  5616.     shl   si,2
  5617.     mov     ax,word ptr [bx+VBMInfoStruc.ImageHeight]
  5618.     mov   VBMHeight,ax
  5619.     mov     ax,word ptr [bx+VBMInfoStruc.ImageWidth]
  5620.     mov   VBMWidth,ax
  5621.     sub   cx,ax
  5622.     mov   NextLineIncr,cx
  5623.     mov   dx,[bx+VBMAlignmentStruc.MaskPtr+AlignData+si]
  5624.     mov   bx,[bx+VBMAlignmentStruc.ImagePtr+AlignData+si]
  5625.     mov   si,dx
  5626.     mov   dx,GCINDEX
  5627.     mov   ax,BITMASK
  5628.     out   dx,ax
  5629.     mov   dx,SCINDEX
  5630.     mov   al,MAPMASK
  5631.     out   dx,al
  5632.     inc   dx
  5633.     mov   ah,byte ptr VBMHeight
  5634.  
  5635. @@RowLoop:
  5636.     mov   cx,VBMWidth
  5637.  
  5638. @@ColumnLoop:
  5639.     lodsb
  5640.     out   dx,al
  5641.     mov   al,es:[bx]
  5642.     stosb
  5643.     inc   bx
  5644.     loop  @@ColumnLoop
  5645.     add   di,NextLineIncr
  5646.     dec   ah
  5647.     jnz   @@RowLoop
  5648.     mov   dx,GCINDEX+1
  5649.     mov   al,0ffh
  5650.     out   dx,al
  5651.     pop   ds
  5652.     pop   di
  5653.     pop   si
  5654. end;
  5655.  
  5656. Procedure XPutMaskedVBMClipX( X, Y, ScrnOffs:word; var SrcVBM ); assembler;
  5657. var
  5658.     DataInc,LeftSkip,VBMWidth,VBMHeight,NextLineIncr:word;
  5659. asm
  5660.     push  si
  5661.     push  di
  5662.     push  ds
  5663.     cld
  5664.     mov   di,X
  5665.     mov   si,di
  5666.     sar   di,2
  5667.     and   si,3
  5668.     shl   si,2
  5669.     les   bx,SrcVBM
  5670.     mov   cx,es:[bx+VBMInfoStruc.ImageWidth]
  5671.     mov   dx,LeftClip
  5672.     sub   dx,di
  5673.     jle   @@NotLeftClip
  5674.     cmp   dx,cx
  5675.     jnl   @@NotVisible
  5676.     add   di,dx
  5677.     mov   LeftSkip,dx
  5678.     mov   DataInc,dx
  5679.     sub   cx,dx
  5680.     jmp   @@HorizClipDone
  5681.  
  5682. @@NotVisible:
  5683.     mov   ax,1
  5684.     jmp     @@Bye
  5685.  
  5686. @@NotLeftClip:
  5687.     mov   dx,RightClip
  5688.     sub   dx,di
  5689.     js    @@NotVisible
  5690.     mov   LeftSkip,0
  5691.     mov   DataInc,0
  5692.     cmp   dx,cx
  5693.     jge   @@HorizClipDone
  5694.     inc   dx
  5695.     sub   cx,dx
  5696.     mov   DataInc,cx
  5697.     mov   cx,dx
  5698.  
  5699. @@HorizClipDone:
  5700.     add   di,ScrnOffs
  5701.     mov   VBMWidth,cx
  5702.     mov   ax,es:[bx+VBMInfoStruc.ImageHeight]
  5703.     mov   VBMHeight,ax
  5704.     mov   ax,Y
  5705.     mov   cx,ScrnLogicalByteWidth
  5706.     mul   cx
  5707.     add   di,ax
  5708.     sub   cx,VBMWidth
  5709.     mov   NextLineIncr,cx
  5710.     mov   ax,es
  5711.     mov   ds,ax
  5712.     mov   ax,SCREENSEG
  5713.     mov   es,ax
  5714.     mov   ax,[bx+VBMAlignmentStruc.MaskPtr+AlignData+si]
  5715.     mov   bx,[bx+VBMAlignmentStruc.ImagePtr+AlignData+si]
  5716.     mov   si,ax
  5717.     mov   ax,LeftSkip
  5718.     add   bx,ax
  5719.     add   si,ax
  5720.     mov   dx,GCINDEX
  5721.     mov   ax,BITMASK
  5722.     out   dx,ax
  5723.     mov   dx,SCINDEX
  5724.     mov   al,MAPMASK
  5725.     out   dx,al
  5726.     inc   dx
  5727.     mov   ah,byte ptr VBMHeight
  5728.  
  5729. @@RowLoop:
  5730.     mov   cx,VBMWidth
  5731.  
  5732. @@ColumnLoop:
  5733.     lodsb
  5734.     out   dx,al
  5735.     mov   al,es:[bx]
  5736.     stosb
  5737.     inc   bx
  5738.     loop  @@ColumnLoop
  5739.     add   bx,DataInc
  5740.     add   si,DataInc
  5741.     add   di,NextLineIncr
  5742.     dec   ah
  5743.     jnz   @@RowLoop
  5744.  
  5745.     mov   dx,GCINDEX+1
  5746.     mov   al,0ffh
  5747.     out   dx,al
  5748.     xor   ax,ax
  5749. @@Bye:
  5750.     pop   ds
  5751.     pop   di
  5752.     pop   si
  5753. end;
  5754.  
  5755. Procedure XPutMaskedVBMClipY( X, Y, ScrnOffs : word; var SrcVBM ); assembler;
  5756. var
  5757.     VBMWidth,VBMHeight,TopRow,NextLineIncr:word;
  5758. asm
  5759.     push  si
  5760.     push  di
  5761.     push  ds
  5762.     cld
  5763.     mov   di,X
  5764.     mov   si,di
  5765.     and   si,3
  5766.     shl   si,2
  5767.     les   bx,SrcVBM
  5768.     mov   ax,es:[bx+VBMInfoStruc.ImageHeight]
  5769.     mov   dx,TopClip
  5770.     sub   dx,Y
  5771.     jle   @@NotTopClip
  5772.     cmp   dx,ax
  5773.     jnl   @@NotVisible
  5774.     mov   TopRow,dx
  5775.     sub   ax,dx
  5776.     add   Y,dx
  5777.     jmp   @@VertClipDone
  5778.  
  5779. @@NotVisible:
  5780.     mov   ax,1
  5781.     jmp   @@Bye
  5782.  
  5783. @@NotTopClip:
  5784.     mov   dx,BottomClip
  5785.     sub   dx,Y
  5786.     js    @@NotVisible
  5787.     mov   TopRow,0
  5788.     cmp   dx,ax
  5789.     jg    @@VertClipDone
  5790.     inc   dx
  5791.     mov   ax,dx
  5792.  
  5793. @@VertClipDone:
  5794.     shr   di,2
  5795.     add   di,ScrnOffs
  5796.     mov   cx,es:[bx+VBMInfoStruc.ImageWidth]
  5797.     mov   VBMWidth,cx
  5798.     mov   VBMHeight,ax
  5799.     mov   ax,Y
  5800.     mov   cx,ScrnLogicalByteWidth
  5801.     mul   cx
  5802.     add   di,ax
  5803.     sub   cx,VBMWidth
  5804.     mov   NextLineIncr,cx
  5805.     mov   ax,es
  5806.     mov   ds,ax
  5807.     mov   ax,SCREENSEG
  5808.     mov   es,ax
  5809.  
  5810.     mov   ax,[bx+VBMAlignmentStruc.MaskPtr+AlignData+si]
  5811.     mov   bx,[bx+VBMAlignmentStruc.ImagePtr+AlignData+si]
  5812.     mov   si,ax
  5813.     mov   ax,VBMWidth
  5814.     mul   TopRow
  5815.     add   bx,ax
  5816.     add   si,ax
  5817.     mov   dx,GCINDEX
  5818.     mov   ax,BITMASK
  5819.     out   dx,ax
  5820.     mov   dx,SCINDEX
  5821.     mov   al,MAPMASK
  5822.     out   dx,al
  5823.     inc   dx
  5824.     mov   ah,byte ptr [VBMHeight]
  5825.  
  5826. @@RowLoop:
  5827.     mov   cx,VBMWidth
  5828.  
  5829. @@ColumnLoop:
  5830.     lodsb
  5831.     out   dx,al
  5832.     mov   al,es:[bx]
  5833.     stosb
  5834.     inc   bx
  5835.     loop  @@ColumnLoop
  5836.     add   di,NextLineIncr
  5837.     dec   ah
  5838.     jnz   @@RowLoop
  5839.     mov   dx,GCINDEX+1
  5840.     mov   al,0ffh
  5841.     out   dx,al
  5842.     xor   ax,ax
  5843. @@Bye:
  5844.     pop   ds
  5845.     pop   di
  5846.     pop   si
  5847. end;
  5848.  
  5849. Procedure XPutMaskedVBMClipXY( X, Y, ScrnOffs:word; var SrcVBM ); assembler;
  5850. var
  5851.     DataInc,LeftSkip,VBMWidth,VBMHeight,TopRow,NextLineIncr:word;
  5852. asm
  5853.     push  si
  5854.     push  di
  5855.     push  ds
  5856.     cld
  5857.     mov   di,X
  5858.     mov   si,di
  5859.     sar   di,2
  5860.     and   si,3
  5861.     shl   si,2
  5862.     les   bx,SrcVBM
  5863.     mov   cx,es:[bx+VBMInfoStruc.ImageWidth]
  5864.     mov   ax,es:[bx+VBMInfoStruc.ImageHeight]
  5865.     mov   dx,TopClip
  5866.     sub   dx,Y
  5867.     jle   @@NotTopClip
  5868.     cmp   dx,ax
  5869.     jnl   @@NotVisible
  5870.     mov   TopRow,dx
  5871.     sub   ax,dx
  5872.     add   Y,dx
  5873.     jmp   @@VertClipDone
  5874.  
  5875. @@NotVisible:
  5876.     mov   ax,1
  5877.     jmp   @@Bye
  5878.  
  5879. @@NotTopClip:
  5880.     mov   dx,BottomClip
  5881.     sub   dx,Y
  5882.     js    @@NotVisible
  5883.     mov   TopRow,0
  5884.     cmp   dx,ax
  5885.     jg    @@VertClipDone
  5886.     inc   dx
  5887.     mov   ax,dx
  5888.  
  5889. @@VertClipDone:
  5890.     mov   dx,LeftClip
  5891.     sub   dx,di
  5892.     jle   @@NotLeftClip
  5893.     cmp   dx,cx
  5894.     jnl   @@NotVisible
  5895.     add   di,dx
  5896.     mov   LeftSkip,dx
  5897.     mov   DataInc,dx
  5898.     sub   cx,dx
  5899.     jmp   @@HorizClipDone
  5900. @@NotLeftClip:
  5901.     mov   dx,RightClip
  5902.     sub   dx,di
  5903.     js    @@NotVisible
  5904.     mov   LeftSkip,0
  5905.     mov   DataInc,0
  5906.     cmp   dx,cx
  5907.     jge   @@HorizClipDone
  5908.     inc   dx
  5909.     sub   cx,dx
  5910.     mov   DataInc,cx
  5911.     mov   cx,dx
  5912.  
  5913. @@HorizClipDone:
  5914.     add   di,ScrnOffs
  5915.     mov   VBMWidth,cx
  5916.     mov   VBMHeight,ax
  5917.     mov   ax,Y
  5918.     mov   cx,ScrnLogicalByteWidth
  5919.     mul   cx
  5920.     add   di,ax
  5921.     sub   cx,VBMWidth
  5922.     mov   NextLineIncr,cx
  5923.     mov   ax,es
  5924.     mov   ds,ax
  5925.     mov   ax,SCREENSEG
  5926.     mov   es,ax
  5927.  
  5928.     mov   ax,[bx+VBMAlignmentStruc.MaskPtr+AlignData+si]
  5929.     mov   bx,[bx+VBMAlignmentStruc.ImagePtr+AlignData+si]
  5930.     mov   si,ax
  5931.     mov   ax,VBMWidth
  5932.     add   ax,DataInc
  5933.     mul   TopRow
  5934.     add   ax,LeftSkip
  5935.     add   bx,ax
  5936.     add   si,ax
  5937.     mov   dx,GCINDEX
  5938.     mov   ax,BITMASK
  5939.     out   dx,ax
  5940.     mov   dx,SCINDEX
  5941.     mov   al,MAPMASK
  5942.     out   dx,al
  5943.     inc   dx
  5944.     mov   ah,byte ptr VBMHeight
  5945.  
  5946. @@RowLoop:
  5947.     mov   cx,VBMWidth
  5948.  
  5949. @@ColumnLoop:
  5950.     lodsb
  5951.     out   dx,al
  5952.     mov   al,es:[bx]
  5953.     stosb
  5954.     inc   bx
  5955.     loop  @@ColumnLoop
  5956.     add   bx,DataInc
  5957.     add   si,DataInc
  5958.     add   di,NextLineIncr
  5959.     dec   ah
  5960.     jnz   @@RowLoop
  5961.  
  5962.     mov   dx,GCINDEX+1
  5963.     mov   al,0ffh
  5964.     out   dx,al
  5965.     xor   ax,ax
  5966. @@Bye:
  5967.     pop   ds
  5968.     pop   di
  5969.     pop   si
  5970. end;
  5971.  
  5972. function XMakeVBM( var lbm; var VramStart : word ) : PAlignmentHeader;
  5973. var
  5974.     LBMHeadr : ^LBMheader;
  5975.     VBMHeadr : PAlignmentHeader;
  5976.     VBMMaskPtr, p, LBMPixelPtr : ^byte;
  5977.     align,BitNum,TempImageWidth, scanline : integer;
  5978.     TempWidth,TempHeight,TempSize,MaskSize,VramOffs,MaskSpace : word;
  5979.     MaskTemp : byte;
  5980. begin
  5981.     VramOffs := VramStart;
  5982.     LBMHeadr := @lbm;
  5983.     TempWidth  := (LBMHeadr^.width+3) div 4+1;
  5984.     TempHeight := LBMHeadr^.height;
  5985.     TempSize   := TempWidth*TempHeight;
  5986.     getmem( VBMHeadr,22+TempSize*4);
  5987.     MaskSpace:=22;
  5988.     VBMHeadr^.ImageWidth  := TempWidth;
  5989.     VBMHeadr^.ImageHeight := TempHeight;
  5990.     VBMHeadr^.size := 22+TempSize*4;
  5991.     for align := 0 to 3 do
  5992.     begin
  5993.         VBMHeadr^.alignments[align].ImagePtr := VramOffs;
  5994.         XStoreVBMImage(VramOffs,align,lbm);
  5995.         MaskSpace := MaskSpace+TempSize;
  5996.         VramOffs := VramOffs+TempSize;
  5997.     end;
  5998.     VBMMaskPtr := ptr(Seg(VBMHeadr^),Ofs(VBMHeadr^)+22);
  5999.     for align:=0 to 3 do
  6000.     begin
  6001.         LBMPixelPtr := ptr(Seg(lbm),Ofs(lbm)+ 2);
  6002.         VBMHeadr^.alignments[align].MaskPtr := Ofs(VBMMaskPtr^);
  6003.         for scanline := 0 to TempHeight-1 do
  6004.         begin
  6005.             BitNum := align;
  6006.             MaskTemp := 0;
  6007.             TempImageWidth := LBMHeadr^.width;
  6008.             repeat
  6009.                 MaskTemp := MaskTemp or (Ord(LBMPixelPtr^<>0) shl BitNum);
  6010.                 LBMPixelPtr := Ptr(Seg(LBMPixelPtr^),Ofs(LBMPixelPtr^)+1);
  6011.                 inc(BitNum);
  6012.                 if BitNum > 3 then
  6013.                 begin
  6014.                     VBMMaskPtr^ := MaskTemp;
  6015.                     VBMMaskPtr := Ptr(Seg(VBMMaskPtr^),Ofs(VBMMaskPtr^)+1);
  6016.                     MaskTemp := 0;
  6017.                     BitNum := 0;
  6018.                 end;
  6019.                 dec(TempImageWidth);
  6020.             until TempImageWidth=0;
  6021.             if BitNum<>0 then VBMMaskPtr^ := MaskTemp else VBMMaskPtr^ := 0;
  6022.             VBMMaskPtr := Ptr(Seg(VBMMaskPtr^),Ofs(VBMMaskPtr^)+1);
  6023.         end;
  6024.     end;
  6025.     VramStart :=VramOffs;
  6026.     XMakeVBM := VBMHeadr;
  6027. end;
  6028.  
  6029. End.